@nice2dev/ui-forms 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NicePinCodeInput-BmRO9HSQ-7FC0AexB.cjs +419 -0
- package/dist/NicePinCodeInput-BmRO9HSQ-CmusgJGw.js +10624 -0
- package/dist/NiceSavedQueryPanel-BSGzs7Oc-Bo9UxBec.cjs +596 -0
- package/dist/NiceSavedQueryPanel-BSGzs7Oc-CjNobdAO.js +6610 -0
- package/dist/charts-DZvmvfhM-DN5tnI16.cjs +544 -0
- package/dist/charts-DZvmvfhM-E0Huk8_7.js +3844 -0
- package/dist/index-CYrOf5uD.js +21039 -0
- package/dist/index-DlHlXz8e-B_hFrHO1.cjs +4504 -0
- package/dist/index-DlHlXz8e-DEMTlEW8.js +35492 -0
- package/dist/index-tVSzr4V7.cjs +404 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),F=require("./index-tVSzr4V7.cjs"),a=require("react");function $t(n,t,i){return Math.max(t,Math.min(i,n))}function Ut({h:n,s:t,v:i}){n=(n%360+360)%360;const r=i*t,d=r*(1-Math.abs(n/60%2-1)),f=i-r;let _=0,M=0,N=0;return n<60?(_=r,M=d):n<120?(_=d,M=r):n<180?(M=r,N=d):n<240?(M=d,N=r):n<300?(_=d,N=r):(_=r,N=d),{r:Math.round((_+f)*255),g:Math.round((M+f)*255),b:Math.round((N+f)*255)}}function yt({r:n,g:t,b:i}){n/=255,t/=255,i/=255;const r=Math.max(n,t,i),d=Math.min(n,t,i),f=r-d;let _=0;return f!==0&&(r===n?_=(t-i)/f%6:r===t?_=(i-n)/f+2:_=(n-t)/f+4,_=(_*60+360)%360),{h:_,s:r===0?0:f/r,v:r}}function Xt({r:n,g:t,b:i}){n/=255,t/=255,i/=255;const r=Math.max(n,t,i),d=Math.min(n,t,i),f=(r+d)/2;if(r===d)return{h:0,s:0,l:f};const _=r-d,M=f>.5?_/(2-r-d):_/(r+d);let N=0;return r===n?N=((t-i)/_+(t<i?6:0))/6:r===t?N=((i-n)/_+2)/6:N=((n-t)/_+4)/6,{h:N*360,s:M,l:f}}function We(n){const t=n.replace("#",""),i=t.length===3?t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t,r=parseInt(i,16);return{r:r>>16&255,g:r>>8&255,b:r&255}}function qt({r:n,g:t,b:i}){return"#"+[n,t,i].map(r=>r.toString(16).padStart(2,"0")).join("")}function Se(n){return qt(Ut(n))}function qe(n){return yt(We(n))}function Yt(n,t){const i=[];for(let r=0;r<t;r++){const d=t<=1?.5:r/(t-1),f=$t(n.s*(.3+d*.7),0,1),_=$t(n.v*(1.2-d*.7),0,1);i.push(Se({h:n.h,s:f,v:_}))}return i}function _t(n,t){if(n==="custom")return[0];const i=t??30;switch(n){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-i,180+i];case"analogous":return[0,-i,i];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270]}}function Je(n,t,i){return _t(t,i).map(r=>((n+r)%360+360)%360)}function Mt({r:n,g:t,b:i}){const[r,d,f]=[n,t,i].map(_=>{const M=_/255;return M<=.03928?M/12.92:Math.pow((M+.055)/1.055,2.4)});return .2126*r+.7152*d+.0722*f}function tt(n,t){const i=Mt(We(n)),r=Mt(We(t)),d=Math.max(i,r),f=Math.min(i,r);return(d+.05)/(f+.05)}function nt(n){return n>=7?"AAA":n>=4.5?"AA":n>=3?"AA-lg":"Fail"}const Jt={"lightest-pastel":{sRange:[.1,.25],vRange:[.92,1]},"bright-pastel":{sRange:[.25,.45],vRange:[.9,1]},shiny:{sRange:[.7,.95],vRange:[.9,1]},pastel:{sRange:[.3,.55],vRange:[.75,.92]},full:{sRange:[.75,1],vRange:[.75,1]},dark:{sRange:[.6,.9],vRange:[.3,.55]},deep:{sRange:[.85,1],vRange:[.45,.65]},muted:{sRange:[.15,.35],vRange:[.5,.7]},earth:{sRange:[.3,.6],vRange:[.4,.65]}};function at(n,t){const i=Jt[t];return n.map(r=>{const d=(i.sRange[0]+i.sRange[1])/2,f=(i.vRange[0]+i.vRange[1])/2;return Se({h:r,s:d,v:f})})}function Tn(){return Math.floor(Math.random()*360)}function Wt(n,t,i){const r=Tn(),d=Je(r,n,i),f=[];for(let _=0;_<t;_++){const M=d[_%d.length],N=.55+Math.random()*.4,z=.5+Math.random()*.45;f.push(Se({h:M+(Math.random()-.5)*8,s:N,v:z}))}return f}const Rn=({hues:n,baseHue:t,onBaseHueChange:i,mode:r,distance:d,disabled:f})=>{const _=a.useCallback(H=>{if(f)return;const g=H.currentTarget.getBoundingClientRect(),k=H.clientX-g.left-120,K=H.clientY-g.top-120,ee=(Math.atan2(K,k)*180/Math.PI+360)%360;i(Math.round(ee))},[120,120,f,i]),M=[];for(let H=0;H<360;H+=2){const g=(H-1)*Math.PI/180,k=(H+1)*Math.PI/180,K=Se({h:H,s:1,v:1});M.push(e.jsx("path",{d:`M${120+55*Math.cos(g)},${120+55*Math.sin(g)} L${120+110*Math.cos(g)},${120+110*Math.sin(g)} A110,110 0 0,1 ${120+110*Math.cos(k)},${120+110*Math.sin(k)} L${120+55*Math.cos(k)},${120+55*Math.sin(k)} A55,55 0 0,0 ${120+55*Math.cos(g)},${120+55*Math.sin(g)} Z`,fill:K},H))}const N=`wheel-center-${r}`,z=n.map((H,g)=>{const k=H*Math.PI/180;return e.jsx("circle",{cx:120+82.5*Math.cos(k),cy:120+82.5*Math.sin(k),r:g===0?8:6,fill:Se({h:H,s:.85,v:.9}),stroke:g===0?"var(--bg-primary, #fff)":"var(--border-color, #ccc)",strokeWidth:g===0?3:2},g)});let V=null;if(r==="analogous"||r==="split-complementary"){const H=_t(r,d).slice(1).map((g,k)=>{const K=(t+g)*Math.PI/180;return e.jsx("line",{x1:120,y1:120,x2:120+82.5*Math.cos(K),y2:120+82.5*Math.sin(K),stroke:"rgba(255,255,255,0.3)",strokeWidth:1,strokeDasharray:"3,3"},`dline-${k}`)});V=e.jsx(e.Fragment,{children:H})}return e.jsxs("svg",{className:"nice-palette__wheel",viewBox:"0 0 240 240",width:240,height:240,onClick:_,style:{cursor:f?"default":"crosshair"},children:[e.jsx("defs",{children:e.jsxs("radialGradient",{id:N,children:[e.jsx("stop",{offset:"0%",stopColor:"#fff"}),e.jsx("stop",{offset:"100%",stopColor:"transparent"})]})}),M,e.jsx("circle",{cx:120,cy:120,r:53,fill:Se({h:t,s:.6,v:.85})}),e.jsx("circle",{cx:120,cy:120,r:53,fill:`url(#${N})`,opacity:.4}),V,z]})},Dn=({colors:n})=>{if(n.length<2)return null;const t=[];for(let i=0;i<n.length;i++){const r=tt(n[i],"var(--bg-primary, #ffffff)"),d=tt(n[i],"var(--text-primary, #000000)");t.push({a:n[i],b:"var(--bg-primary, #ffffff)",ratio:r,level:nt(r)}),t.push({a:n[i],b:"var(--text-primary, #000000)",ratio:d,level:nt(d)});for(let f=i+1;f<n.length;f++){const _=tt(n[i],n[f]);t.push({a:n[i],b:n[f],ratio:_,level:nt(_)})}}return e.jsxs("div",{className:"nice-palette__contrast",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Contrast Analysis (WCAG 2.1)"}),e.jsx("div",{className:"nice-palette__contrast-grid",children:t.map((i,r)=>e.jsxs("div",{className:"nice-palette__contrast-pair",children:[e.jsxs("div",{className:"nice-palette__contrast-swatches",children:[e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:i.a}}),e.jsx("span",{className:"nice-palette__contrast-vs",children:"vs"}),e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:i.b}})]}),e.jsxs("span",{className:"nice-palette__contrast-ratio",children:[i.ratio.toFixed(1),":1"]}),e.jsx("span",{className:`nice-palette__contrast-level nice-palette__contrast-level--${i.level.toLowerCase().replace("-","")}`,children:i.level})]},r))})]})},An=({hex:n})=>{const t=We(n),i=Xt(t),r=yt(t);return e.jsxs("div",{className:"nice-palette__color-info",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"HEX"})," ",n.toUpperCase()]}),e.jsxs("div",{children:[e.jsx("strong",{children:"RGB"})," ",t.r,", ",t.g,", ",t.b]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSL"})," ",Math.round(i.h),"°, ",Math.round(i.s*100),"%,"," ",Math.round(i.l*100),"%"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSV"})," ",Math.round(r.h),"°, ",Math.round(r.s*100),"%,"," ",Math.round(r.v*100),"%"]})]})},St={monochromatic:"Monochromatic",complementary:"Complementary","split-complementary":"Split-Complementary",analogous:"Analogous",triadic:"Triadic",tetradic:"Tetradic (Rectangle)",square:"Square",custom:"Custom"},zn={"lightest-pastel":"Lightest Pastel","bright-pastel":"Bright Pastel",shiny:"Shiny",pastel:"Pastel",full:"Full Colors",dark:"Dark",deep:"Deep Colors",muted:"Muted",earth:"Earth Tones"},In=["monochromatic","complementary","split-complementary","analogous","triadic","tetradic","square","custom"],Qt=a.forwardRef(({id:n,className:t,style:i,accessMode:r,value:d,onChange:f,minColors:_=1,maxColors:M=8,harmonyMode:N,onHarmonyModeChange:z,distance:V,onDistanceChange:H,preset:g,onPresetChange:k,showWheel:K=!0,showContrast:ee=!0,showInfo:X=!0,showPresets:S=!0,presets:v=[],showVariations:I=!0,showRandom:j=!0,variationCount:A=5,label:Y,disabled:b},h)=>{const C=F.rl(r,n);if(C==="hidden")return null;(C==="disabled"||C==="readOnly")&&(b=!0);const w=F.Os(n),[O,L]=a.useState("analogous"),[x,p]=a.useState(30),[R,y]=a.useState(""),[u,s]=a.useState(0),c=N??O,l=V??x,o=g??R,E=a.useCallback(Q=>{L(Q),z==null||z(Q)},[z]),J=a.useCallback(Q=>{p(Q),H==null||H(Q)},[H]),te=a.useCallback(Q=>{y(Q),Q&&(k==null||k(Q))},[k]),q=a.useMemo(()=>["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)"],[]),$=d&&d.length>0?d:q,P=$[0],W=a.useMemo(()=>qe(P),[P]),le=a.useMemo(()=>Je(W.h,c,l),[W.h,c,l]),re=a.useCallback((Q,B,ie,oe)=>{const ke=Je(Q,B,ie);let ge;for(oe&&Jt[oe]?ge=at(ke,oe):ge=ke.map(ye=>Se({h:ye,s:W.s||.7,v:W.v||.85}));ge.length<_;)ge.push(ge[ge.length-1]||"#888888");ge.length>M&&(ge=ge.slice(0,M)),f==null||f(ge)},[W.s,W.v,_,M,f]),pe=a.useCallback(Q=>{if(!b){if(c==="custom"){const B=Se({h:Q,s:W.s||.7,v:W.v||.85}),ie=[...$];ie[u]=B,f==null||f(ie);return}re(Q,c,l,o)}},[b,c,l,o,re,W.s,W.v,$,u,f]),me=a.useCallback(Q=>{b||(E(Q),Q!=="custom"&&re(W.h,Q,l,o))},[b,W.h,l,o,E,re]),Ne=a.useCallback(Q=>{b||(J(Q),re(W.h,c,Q,o))},[b,W.h,c,o,J,re]),ne=a.useCallback(Q=>{if(b)return;te(Q);const B=Je(W.h,c,l),ie=at(B,Q);f==null||f(ie.slice(0,M))},[b,W.h,c,l,M,te,f]),de=a.useCallback((Q,B)=>{if(b)return;const ie=[...$];ie[Q]=B,f==null||f(ie)},[b,$,f]),ue=a.useCallback(()=>{if(b||$.length>=M)return;const Q=qe($[$.length-1]),B=Se({h:(Q.h+30)%360,s:Q.s,v:Q.v});f==null||f([...$,B])},[b,$,M,f]),ve=a.useCallback(Q=>{if(b||$.length<=_)return;const B=$.filter((ie,oe)=>oe!==Q);f==null||f(B),u>=B.length&&s(Math.max(0,B.length-1))},[b,$,_,f,u]),se=a.useCallback(()=>{if(b)return;const Q=Math.max(_,Math.min(M,_t(c).length)),B=Wt(c,Q,l);f==null||f(B)},[b,_,M,c,l,f]),D=a.useMemo(()=>{if(!I)return[];const Q=$[u]||$[0];return Yt(qe(Q),A)},[I,$,u,A]),T=$[u]||$[0],ae=a.useMemo(()=>{const Q=qe(T);return Se({h:(Q.h+180)%360,s:Q.s,v:Q.v})},[T]);return e.jsxs("div",{ref:h,id:w,className:`nice-palette ${b?"nice-palette--disabled":""} ${t||""}`,style:i,children:[Y&&e.jsx("div",{className:"nice-palette__label",children:Y}),e.jsx("div",{className:"nice-palette__modes",children:In.map(Q=>e.jsx("button",{type:"button",className:`nice-palette__mode-btn ${c===Q?"nice-palette__mode-btn--active":""}`,onClick:()=>me(Q),disabled:b,title:St[Q],children:St[Q]},Q))}),e.jsxs("div",{className:"nice-palette__main",children:[K&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Rn,{hues:le,baseHue:W.h,onBaseHueChange:pe,mode:c,distance:l,disabled:b}),(c==="analogous"||c==="split-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsxs("label",{children:["Distance: ",l,"°"]}),e.jsx("input",{type:"range",min:10,max:90,value:l,onChange:Q=>Ne(Number(Q.target.value)),disabled:b,className:"nice-palette__distance-slider"})]})]}),e.jsxs("div",{className:"nice-palette__strips",children:[e.jsxs("div",{className:"nice-palette__swatches",children:[$.map((Q,B)=>e.jsxs("div",{className:`nice-palette__swatch-wrapper ${u===B?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>s(B),children:[e.jsx("div",{className:"nice-palette__swatch",style:{background:Q},children:$.length>_&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:ie=>{ie.stopPropagation(),ve(B)},disabled:b,"aria-label":"Remove color",children:"×"})}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:Q.toUpperCase(),maxLength:7,disabled:b,onChange:ie=>de(B,ie.target.value)})]},B)),$.length<M&&e.jsx("button",{type:"button",className:"nice-palette__add-btn",onClick:ue,disabled:b,title:"Add color",children:"+"})]}),e.jsxs("div",{className:"nice-palette__complementary",children:[e.jsx("span",{className:"nice-palette__section-tag",children:"Complementary"}),e.jsx("div",{className:"nice-palette__swatch nice-palette__swatch--sm",style:{background:ae},title:ae.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:ae.toUpperCase()})]}),I&&D.length>0&&e.jsxs("div",{className:"nice-palette__variations",children:[e.jsx("span",{className:"nice-palette__section-tag",children:"Tints & Shades"}),e.jsx("div",{className:"nice-palette__variation-strip",children:D.map((Q,B)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:Q},title:Q.toUpperCase(),onClick:()=>{b||de(u,Q)},role:"button",tabIndex:0},B))})]}),j&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:se,disabled:b,title:"Random palette","aria-label":"Random palette",children:"🎲 Random Palette"})]})]}),S&&v.length>0&&e.jsxs("div",{className:"nice-palette__presets",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Style Presets"}),e.jsx("div",{className:"nice-palette__preset-grid",children:v.map(Q=>{const B=at(le,Q);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${o===Q?"nice-palette__preset-card--active":""}`,onClick:()=>ne(Q),disabled:b,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:B.map((ie,oe)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:ie}},oe))}),e.jsx("span",{className:"nice-palette__preset-label",children:zn[Q]})]},Q)})})]}),X&&e.jsxs("div",{className:"nice-palette__info-panel",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Selected Color Info"}),e.jsx(An,{hex:T})]}),ee&&e.jsxs("details",{className:"nice-palette__contrast-popup",style:{marginTop:8},children:[e.jsx("summary",{style:{cursor:"pointer",padding:"6px 10px",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border-color)",borderRadius:4,display:"inline-block",fontSize:12,userSelect:"none"},children:"Contrast Analysis (WCAG 2.1)"}),e.jsx("div",{style:{marginTop:8},children:e.jsx(Dn,{colors:$})})]})]})});Qt.displayName="NiceColorPalette";function gt(){return{type:"linear",angle:90,stops:[{color:"#3b82f6",position:0},{color:"#8b5cf6",position:100}]}}function ft(n){const t=n.stops.slice().sort((r,d)=>r.position-d.position).map(r=>`${r.color} ${r.position}%`).join(", "),i=n.repeating?"repeating-":"";switch(n.type){case"linear":return`${i}linear-gradient(${n.angle}deg, ${t})`;case"radial":{const r=n.shape||"ellipse",d=n.size||"farthest-corner",f=n.positionX??50,_=n.positionY??50;return`${i}radial-gradient(${r} ${d} at ${f}% ${_}%, ${t})`}case"conic":{const r=n.angle??0,d=n.positionX??50,f=n.positionY??50;return`${i}conic-gradient(from ${r}deg at ${d}% ${f}%, ${t})`}}}function Gt(n){var r,d,f;const t=n.trim(),i=t.startsWith("repeating-");if(t.includes("linear-gradient")){const _=(r=t.match(/linear-gradient\((.+)\)/))==null?void 0:r[1];if(!_)return null;const M=_.split(",").map(g=>g.trim());let N=90,z=0;const V=M[0].match(/^(\d+)deg$/);V&&(N=parseInt(V[1]),z=1);const H=pt(M.slice(z));return{type:"linear",angle:N,repeating:i,stops:H}}if(t.includes("radial-gradient")){const _=(d=t.match(/radial-gradient\((.+)\)/))==null?void 0:d[1];if(!_)return null;const M=_.split(",").map(z=>z.trim()),N=pt(M.filter(z=>z.includes("#")||z.includes("rgb")));return{type:"radial",angle:0,repeating:i,stops:N.length>=2?N:gt().stops}}if(t.includes("conic-gradient")){const _=(f=t.match(/conic-gradient\((.+)\)/))==null?void 0:f[1];if(!_)return null;const M=_.split(",").map(z=>z.trim()),N=pt(M.filter(z=>z.includes("#")||z.includes("rgb")));return{type:"conic",angle:0,repeating:i,stops:N.length>=2?N:gt().stops}}return null}function pt(n){return n.map((t,i,r)=>{const d=t.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(d){const f=d[2]?parseFloat(d[2]):i/Math.max(1,r.length-1)*100;return{color:d[1],position:f}}return{color:t,position:i/Math.max(1,r.length-1)*100}})}function Ln(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function On(n=2){const t=["linear","radial","conic"],i=t[Math.floor(Math.random()*t.length)],r=[];for(let d=0;d<n;d++)r.push({color:Ln(),position:Math.round(d/(n-1)*100)});return{type:i,angle:Math.floor(Math.random()*360),stops:r,shape:i==="radial"?Math.random()>.5?"circle":"ellipse":void 0,positionX:i!=="linear"?Math.round(Math.random()*100):void 0,positionY:i!=="linear"?Math.round(Math.random()*100):void 0}}const Zt=[{name:"Sunset",value:{type:"linear",angle:135,stops:[{color:"#ff6b6b",position:0},{color:"#feca57",position:100}]}},{name:"Ocean",value:{type:"linear",angle:180,stops:[{color:"#667eea",position:0},{color:"#764ba2",position:100}]}},{name:"Forest",value:{type:"linear",angle:120,stops:[{color:"#11998e",position:0},{color:"#38ef7d",position:100}]}},{name:"Fire",value:{type:"linear",angle:90,stops:[{color:"#f12711",position:0},{color:"#f5af19",position:100}]}},{name:"Aurora",value:{type:"linear",angle:135,stops:[{color:"#a18cd1",position:0},{color:"#fbc2eb",position:50},{color:"#a6c1ee",position:100}]}},{name:"Midnight",value:{type:"linear",angle:180,stops:[{color:"#0f0c29",position:0},{color:"#302b63",position:50},{color:"#24243e",position:100}]}},{name:"Candy",value:{type:"linear",angle:45,stops:[{color:"#fc5c7d",position:0},{color:"#6a82fb",position:100}]}},{name:"Radial Glow",value:{type:"radial",angle:0,shape:"circle",stops:[{color:"#ffecd2",position:0},{color:"#fcb69f",position:100}],positionX:50,positionY:50}},{name:"Rainbow",value:{type:"conic",angle:0,stops:[{color:"#ff0000",position:0},{color:"#ff8800",position:17},{color:"#ffff00",position:33},{color:"#00ff00",position:50},{color:"#0088ff",position:67},{color:"#8800ff",position:83},{color:"#ff0000",position:100}],positionX:50,positionY:50}}],en=a.forwardRef(({id:n,className:t,style:i,accessMode:r,value:d,onChange:f,showCssOutput:_=!0,showPresets:M=!0,showEditor:N=!0,showRandom:z=!0,maxStops:V=10,label:H,disabled:g,width:k},K)=>{const ee=F.rl(r,n);if(ee==="hidden")return null;(ee==="disabled"||ee==="readOnly")&&(g=!0);const X=F.Os(n),S=d??gt(),v=a.useMemo(()=>ft(S),[S]),[I,j]=a.useState(0),[A,Y]=a.useState(""),b=a.useRef(null),h=a.useCallback(l=>{f==null||f(l)},[f]),C=a.useCallback(l=>{g||h({...S,type:l})},[g,S,h]),w=a.useCallback(l=>{g||h({...S,angle:l})},[g,S,h]),O=a.useCallback(l=>{g||h({...S,repeating:l})},[g,S,h]),L=a.useCallback(l=>{g||h({...S,shape:l})},[g,S,h]),x=a.useCallback((l,o)=>{if(g)return;const E=S.stops.map((J,te)=>te===l?{...J,...o}:J);h({...S,stops:E})},[g,S,h]),p=a.useCallback(()=>{if(g||S.stops.length>=V)return;const l=S.stops.slice().sort((q,$)=>q.position-$.position);let o=0,E=l[0];for(let q=0;q<l.length-1;q++){const $=l[q+1].position-l[q].position;$>o&&(o=$,E=l[q])}const J=Math.round(E.position+o/2),te="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");h({...S,stops:[...S.stops,{color:te,position:J}]})},[g,S,V,h]),R=a.useCallback(l=>{if(g||S.stops.length<=2)return;const o=S.stops.filter((E,J)=>J!==l);h({...S,stops:o}),I>=o.length&&j(o.length-1)},[g,S,I,h]),y=a.useCallback(()=>{if(g)return;const l=2+Math.floor(Math.random()*3);h(On(l))},[g,h]),u=a.useCallback(()=>{if(g||!A.trim())return;const l=Gt(A);l&&h(l)},[g,A,h]),s=a.useCallback(l=>{if(g||!b.current||S.stops.length>=V)return;const o=b.current.getBoundingClientRect(),E=Math.round((l.clientX-o.left)/o.width*100),J="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),te=[...S.stops,{color:J,position:E}];h({...S,stops:te}),j(te.length-1)},[g,S,V,h]),c=a.useMemo(()=>S.stops.slice().sort((l,o)=>l.position-o.position),[S.stops]);return e.jsxs("div",{ref:K,id:X,className:`nice-gradient ${g?"nice-gradient--disabled":""} ${t||""}`,style:{width:k!=null?typeof k=="number"?`${k}px`:k:320,boxSizing:"border-box",...i},children:[H&&e.jsx("div",{className:"nice-gradient__label",children:H}),e.jsx("div",{className:"nice-gradient__preview",style:{background:v}}),N&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-gradient__type-row",children:[["linear","radial","conic"].map(l=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${S.type===l?"nice-gradient__type-btn--active":""}`,onClick:()=>C(l),disabled:g,children:l.charAt(0).toUpperCase()+l.slice(1)},l)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:S.repeating??!1,onChange:l=>O(l.target.checked),disabled:g}),"Repeating"]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[S.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Angle: ",S.angle,"°"]}),e.jsx("input",{type:"range",min:0,max:360,value:S.angle,onChange:l=>w(Number(l.target.value)),disabled:g,className:"nice-gradient__slider"}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(l=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${S.angle===l?"nice-gradient__angle-btn--active":""}`,onClick:()=>w(l),disabled:g,title:`${l}°`,children:e.jsx("span",{style:{transform:`rotate(${l}deg)`,display:"inline-block"},children:"→"})},l))})]}),S.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:"Shape:"}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(l=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(S.shape||"ellipse")===l?"nice-gradient__shape-btn--active":""}`,onClick:()=>L(l),disabled:g,children:l},l))})]}),(S.type==="radial"||S.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Center: ",S.positionX??50,"%, ",S.positionY??50,"%"]}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:S.positionX??50,onChange:l=>h({...S,positionX:Number(l.target.value)}),disabled:g,className:"nice-gradient__slider"}),e.jsx("input",{type:"range",min:0,max:100,value:S.positionY??50,onChange:l=>h({...S,positionY:Number(l.target.value)}),disabled:g,className:"nice-gradient__slider"})]})]}),S.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Start angle: ",S.angle,"°"]}),e.jsx("input",{type:"range",min:0,max:360,value:S.angle,onChange:l=>w(Number(l.target.value)),disabled:g,className:"nice-gradient__slider"})]})]}),e.jsxs("div",{className:"nice-gradient__bar-container",children:[e.jsx("div",{ref:b,className:"nice-gradient__bar",style:{background:v},onClick:s,children:S.stops.map((l,o)=>e.jsx("div",{className:`nice-gradient__stop-marker ${I===o?"nice-gradient__stop-marker--active":""}`,style:{left:`${l.position}%`},onClick:E=>{E.stopPropagation(),j(o)},title:`${l.color} @ ${l.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:l.color}})},o))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:p,disabled:g||S.stops.length>=V,title:"Add stop",children:"+"})]}),e.jsx("div",{className:"nice-gradient__stop-editor",children:e.jsx("div",{className:"nice-gradient__stop-list",children:c.map((l,o)=>{const E=S.stops.indexOf(l);return e.jsxs("div",{className:`nice-gradient__stop-row ${I===E?"nice-gradient__stop-row--active":""}`,onClick:()=>j(E),children:[e.jsx("input",{type:"color",value:l.color,onChange:J=>x(E,{color:J.target.value}),disabled:g,className:"nice-gradient__stop-color"}),e.jsx("input",{type:"text",value:l.color.toUpperCase(),maxLength:7,onChange:J=>x(E,{color:J.target.value}),disabled:g,className:"nice-gradient__stop-hex"}),e.jsx("input",{type:"number",min:0,max:100,value:l.position,onChange:J=>x(E,{position:Number(J.target.value)}),disabled:g,className:"nice-gradient__stop-pos"}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),S.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>R(E),disabled:g,"aria-label":"Remove stop",children:"×"})]},E)})})})]}),z&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:y,disabled:g,title:"Random gradient","aria-label":"Random gradient",children:"🎲 Random Gradient"}),M&&e.jsxs("div",{className:"nice-gradient__presets",children:[e.jsx("div",{className:"nice-gradient__section-title",children:"Presets"}),e.jsx("div",{className:"nice-gradient__preset-grid",children:Zt.map((l,o)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{g||h(l.value)},disabled:g,title:l.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:ft(l.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:l.name})]},o))})]}),_&&e.jsxs("div",{className:"nice-gradient__css",children:[e.jsx("div",{className:"nice-gradient__section-title",children:"CSS Output"}),e.jsxs("div",{className:"nice-gradient__css-output",children:[e.jsx("code",{children:`background: ${v};`}),e.jsx("button",{type:"button",className:"nice-gradient__copy-btn",onClick:()=>{var l;return(l=navigator.clipboard)==null?void 0:l.writeText(`background: ${v};`)},title:"Copy CSS",children:"📋"})]}),e.jsxs("div",{className:"nice-gradient__css-import",children:[e.jsx("input",{type:"text",className:"nice-gradient__css-input",placeholder:"Paste CSS gradient to import...",value:A,onChange:l=>Y(l.target.value),disabled:g}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:u,disabled:g,children:"Import"})]})]})]})});en.displayName="NiceGradientPicker";const Fn=({options:n,value:t,onChange:i,searchable:r=!0,clearable:d,loading:f,placeholder:_,label:M,error:N,helperText:z,required:V,disabled:H,size:g="md",id:k,className:K,style:ee,data:X,columns:S,valueField:v="id",displayField:I,dropdownWidth:j,controlWidth:A})=>{var l;const Y=F.Os(k),{t:b}=F.ue(),[h,C]=a.useState(!1),[w,O]=a.useState(""),L=a.useRef(null);F.Is(L,()=>C(!1));const x=!!(X&&S&&S.length>0),p=I??(S&&((l=S[0])==null?void 0:l.key)),R=a.useMemo(()=>!x||!X?[]:X.map(o=>({value:String(o[v]??""),label:p?String(o[p]??""):""})),[x,X,v,p]),y=x?R:n??[],u=y.find(o=>String(o.value)===t),s=a.useMemo(()=>{if(!x||!X)return[];if(!w)return X;const o=w.toLowerCase();return X.filter(E=>S.some(J=>String(E[J.key]??"").toLowerCase().includes(o)))},[x,X,S,w]),c=a.useMemo(()=>{if(x||!w)return y;const o=w.toLowerCase();return y.filter(E=>E.label.toLowerCase().includes(o))},[y,w,x]);return e.jsxs("div",{className:`nice-field nice-field--${g} ${N?"nice-field--error":""} ${K||""}`,style:{width:A!=null?typeof A=="number"?`${A}px`:A:"fit-content",...ee},ref:L,children:[M&&e.jsxs("label",{className:"nice-field__label",htmlFor:Y,children:[M,V&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{className:"nice-field__input-wrap",style:{position:"relative"},children:[e.jsxs("button",{type:"button",id:Y,className:"nice-select__trigger",onClick:()=>!H&&C(!h),disabled:H,children:[e.jsx("span",{children:(u==null?void 0:u.label)||_||b("controls.select","Select...")}),e.jsx("span",{className:"nice-select__arrow",children:"▾"})]}),d&&t&&!H&&e.jsx("button",{type:"button",className:"nice-field__clear",onClick:()=>i(""),"aria-label":b("controls.clear","Clear"),children:"✕"}),h&&e.jsxs("div",{className:"nice-dropdown nice-lookup__dropdown",style:{position:"absolute",top:"100%",left:0,zIndex:50,marginTop:4,background:"var(--bg-primary)",border:"1px solid var(--border-color)",borderRadius:"var(--nice-radius-md)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",minWidth:"100%",width:j!=null?typeof j=="number"?`${j}px`:j:x?"max-content":"100%"},children:[r&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:w,onChange:o=>O(o.target.value),placeholder:b("controls.search","Search..."),autoFocus:!0,style:{width:"100%",padding:"4px 8px",border:"1px solid var(--border-color)",borderRadius:4,background:"var(--bg-primary)",color:"var(--text-primary)"}})}),x?e.jsxs("table",{className:"nice-lookup__grid",role:"listbox",style:{width:"100%",borderCollapse:"collapse",color:"var(--text-primary)"},children:[e.jsx("thead",{children:e.jsx("tr",{children:S.map(o=>e.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontSize:12,fontWeight:600,color:"var(--text-secondary)",background:"var(--bg-secondary)",borderBottom:"1px solid var(--border-color)",width:o.width!=null?typeof o.width=="number"?`${o.width}px`:o.width:void 0},children:o.header},o.key))})}),e.jsx("tbody",{children:s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:S.length,style:{padding:12,textAlign:"center",color:"var(--text-muted)"},children:b("controls.noResults","No results")})}):s.map(o=>{const E=String(o[v]??""),J=E===t;return e.jsx("tr",{role:"option","aria-selected":J,onClick:()=>{i(E),C(!1),O("")},style:{cursor:"pointer",background:J?"var(--hover-bg)":"transparent"},onMouseEnter:te=>{J||(te.currentTarget.style.background="var(--hover-bg)")},onMouseLeave:te=>{J||(te.currentTarget.style.background="transparent")},children:S.map(te=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--border-color)"},children:String(o[te.key]??"")},te.key))},E)})})]}):e.jsx("ul",{className:"nice-dropdown__list",role:"listbox",style:{listStyle:"none",margin:0,padding:4,maxHeight:240,overflowY:"auto"},children:c.length===0?e.jsx("li",{className:"nice-dropdown__empty",style:{padding:8,color:"var(--text-muted)"},children:b("controls.noResults","No results")}):c.map(o=>e.jsx("li",{role:"option",className:`nice-dropdown__option ${String(o.value)===t?"nice-dropdown__option--selected":""}`,onClick:()=>{i(String(o.value)),C(!1),O("")},"aria-selected":String(o.value)===t,children:o.label},String(o.value)))})]})]}),N&&e.jsx("div",{className:"nice-field__error",children:N}),z&&!N&&e.jsx("div",{className:"nice-field__hint",children:z})]})},Pn=["Su","Mo","Tu","We","Th","Fr","Sa"];function Hn(n,t){return new Date(n,t+1,0).getDate()}function Kn(n,t){return new Date(n,t,1).getDay()}function Et(n,t,i){return`${n}-${String(t+1).padStart(2,"0")}-${String(i).padStart(2,"0")}`}function Bn(n){const t=new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()));t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));const i=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-i.getTime())/864e5+1)/7)}const Tt=["January","February","March","April","May","June","July","August","September","October","November","December"],tn=({value:n,onChange:t,min:i,max:r,disabledDates:d=[],firstDayOfWeek:f=1,size:_="md",showWeekNumbers:M,onMonthChange:N,className:z,style:V,accessMode:H,id:g,multiple:k,selectedDates:K=[],onSelectedDatesChange:ee,renderDay:X,showKeyboardHints:S,persistPreferences:v=!1,fullWidth:I=!1,cookies:j=!1,localStorage:A=!0,sessionStorage:Y=!1,storageMode:b,storageKey:h})=>{const C=F.rl(H,g);if(C==="hidden")return null;const w=C==="disabled"||C==="readOnly",{t:O}=F.ue(),L=new Date,x=n?new Date(n):L,p=F.la(h??"nice-calendar"),R=a.useMemo(()=>v?p.get("prefs")??{}:{},[v,p]),y=R.firstDayOfWeek??f,[u,s]=a.useState(R.lastViewYear??x.getFullYear()),[c,l]=a.useState(R.lastViewMonth??x.getMonth()),[o,E]=a.useState(R.preferredView??"days"),J=a.useCallback(B=>{if(!v)return;const ie=p.get("prefs")??{};p.set("prefs",{...ie,...B})},[v,p]),te=a.useCallback(B=>{E(B),J({preferredView:B})},[J]),q=a.useCallback((B,ie)=>{J({lastViewYear:B,lastViewMonth:ie})},[J]),$=a.useMemo(()=>[F.yl.moveUp,F.yl.moveDown,F.yl.moveLeft,F.yl.moveRight,{key:"Enter",description:O("shortcuts.selectDate","Select date")},F.yl.pageUp,F.yl.pageDown],[O]),P=a.useMemo(()=>Hn(u,c),[u,c]),W=a.useMemo(()=>(Kn(u,c)-y+7)%7,[u,c,y]),le=a.useMemo(()=>{const B=[...Pn];for(let ie=0;ie<y;ie++)B.push(B.shift());return B},[y]),re=a.useCallback(B=>i&&B<i||r&&B>r?!0:d.includes(B),[i,r,d]),pe=a.useCallback(B=>{if(o==="years"){s(ke=>ke+B*10);return}if(o==="months"){s(ke=>ke+B);return}let ie=c+B,oe=u;ie<0&&(ie=11,oe--),ie>11&&(ie=0,oe++),l(ie),s(oe),q(oe,ie),N==null||N(oe,ie)},[c,u,N,o,q]),me=Et(L.getFullYear(),L.getMonth(),L.getDate()),Ne=a.useCallback(B=>k?K.includes(B):B===n,[k,K,n]),ne=a.useCallback(B=>{if(!w){if(k){const ie=K.includes(B)?K.filter(oe=>oe!==B):[...K,B];ee==null||ee(ie)}t==null||t(B)}},[k,K,t,ee]),de=a.useCallback(()=>{o==="days"?te("months"):o==="months"&&te("years")},[o,te]),ue=a.useCallback(B=>{l(B),te("days"),q(u,B),N==null||N(u,B)},[u,N,te,q]),ve=a.useCallback(B=>{s(B),te("months")},[te]),se=o==="years"?`${u-u%10} – ${u-u%10+9}`:o==="months"?`${u}`:`${Tt[c]} ${u}`,D=o==="years"?"decade":o==="months"?"year":"month",T=[];for(let B=0;B<W;B++)T.push(null);for(let B=1;B<=P;B++)T.push(B);for(;T.length%7!==0;)T.push(null);const ae=[];for(let B=0;B<T.length;B+=7)ae.push(T.slice(B,B+7));const Q=u-u%10;return e.jsxs("div",{className:`nice-calendar nice-calendar--${_}${I?" nice-calendar--full-width":""} ${z||""}`,style:V,children:[e.jsxs("div",{className:"nice-calendar__header",children:[e.jsx("button",{type:"button",className:"nice-calendar__nav",onClick:()=>pe(-1),"aria-label":`Previous ${D}`,children:"‹"}),e.jsx("button",{type:"button",className:"nice-calendar__title",onClick:de,"aria-label":o==="days"?"Show month picker":o==="months"?"Show year picker":void 0,disabled:o==="years",children:se}),e.jsx("button",{type:"button",className:"nice-calendar__nav",onClick:()=>pe(1),"aria-label":`Next ${D}`,children:"›"}),S&&e.jsx(F.zr,{shortcuts:$,size:"sm"})]}),o==="days"&&e.jsxs("table",{className:"nice-calendar__grid",role:"grid",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[M&&e.jsx("th",{className:"nice-calendar__wk",children:"W"}),le.map(B=>e.jsx("th",{children:B},B))]})}),e.jsx("tbody",{children:ae.map((B,ie)=>e.jsxs("tr",{children:[M&&e.jsx("td",{className:"nice-calendar__wk",children:B.find(oe=>oe!=null)?Bn(new Date(u,c,B.find(oe=>oe!=null))):""}),B.map((oe,ke)=>{if(oe==null)return e.jsx("td",{className:"nice-calendar__empty-cell"},ke);const ge=Et(u,c,oe),ye=re(ge),Me=Ne(ge);return e.jsx("td",{className:`nice-calendar__day${Me?" nice-calendar__day--selected":""}${ge===me?" nice-calendar__day--today":""}${ye?" nice-calendar__day--disabled":""}`,onClick:()=>!ye&&ne(ge),role:"gridcell","aria-selected":Me,"aria-disabled":ye,children:X?X(ge,oe):oe},ke)})]},ie))})]}),o==="months"&&e.jsx("div",{className:"nice-calendar__picker-grid",children:Tt.map((B,ie)=>e.jsx("button",{type:"button",className:`nice-calendar__picker-cell${ie===c&&u===x.getFullYear()?" nice-calendar__picker-cell--selected":""}`,onClick:()=>ue(ie),children:B.slice(0,3)},ie))}),o==="years"&&e.jsx("div",{className:"nice-calendar__picker-grid",children:Array.from({length:12},(B,ie)=>Q-1+ie).map(B=>e.jsx("button",{type:"button",className:`nice-calendar__picker-cell${B===u?" nice-calendar__picker-cell--selected":""}${B<Q||B>Q+9?" nice-calendar__picker-cell--other":""}`,onClick:()=>ve(B),children:B},B))})]})};tn.displayName="NiceCalendar";const Vn=({startDate:n,endDate:t,onStartChange:i,onEndChange:r,min:d,max:f,clearable:_,startPlaceholder:M,endPlaceholder:N,startLabel:z,endLabel:V,layout:H="horizontal",separator:g="–",gap:k=12,fullWidth:K=!1,label:ee,error:X,helperText:S,required:v,disabled:I,size:j="md",id:A,className:Y,style:b,accessMode:h,showKeyboardHints:C,labelPlacement:w,errorPlacement:O,labelWidth:L,controlWidth:x,loading:p})=>{const R=F.rl(h,A),y=F.Os(A),{t:u}=F.ue(),s=R==="disabled"||R==="readOnly"||!!I,c=a.useMemo(()=>[{key:"Tab",description:u("shortcuts.switchField","Switch between start/end")},F.yl.cancel],[u]);if(R==="hidden")return null;const l=E=>{i(E),E&&t&&E>t&&r(E)},o=H==="horizontal";return e.jsxs("div",{className:`nice-field nice-field--${j} nice-daterange nice-daterange--${H} ${w==="left"?"nice-field--label-left":""} ${X?"nice-field--error":""} ${p?"nice-field--loading":""} ${Y||""}`,style:{...b,...L!=null&&{"--nice-field-label-width":typeof L=="number"?`${L}px`:L},...x!=null&&{"--nice-field-control-width":typeof x=="number"?`${x}px`:x}},"aria-busy":p||void 0,children:[ee&&e.jsxs("label",{className:"nice-field__label",htmlFor:y,children:[ee,v&&e.jsx("span",{className:"nice-field__required",children:"*"}),C&&e.jsx(F.zr,{shortcuts:c,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:o?"row":"column",alignItems:o?"flex-end":"stretch",gap:k,flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:K?"1 1 0":void 0,minWidth:0},children:e.jsx(F.pn,{id:y,label:z,value:n,onChange:l,min:d,max:t||f,placeholder:M||u("controls.startDate","Start date"),disabled:s,size:j,clearable:_,labelPlacement:w,labelWidth:L})}),o&&g!==""&&g!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--text-secondary, #666)"},"aria-hidden":"true",children:g}),e.jsx("div",{style:{flex:K?"1 1 0":void 0,minWidth:0},children:e.jsx(F.pn,{label:V,value:t,onChange:r,min:n||d,max:f,placeholder:N||u("controls.endDate","End date"),disabled:s,size:j,clearable:_,labelPlacement:w,labelWidth:L})})]}),p&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),O==="right"&&X&&e.jsx("div",{className:"nice-field__error",role:"alert",children:X}),O==="right"&&!X&&S&&e.jsx("div",{className:"nice-field__helper",children:S})]}),O!=="right"&&X&&e.jsx("div",{className:"nice-field__error",children:X}),O!=="right"&&!X&&S&&e.jsx("div",{className:"nice-field__hint",children:S})]})},Un=({min:n=0,max:t=100,step:i=1,startValue:r,endValue:d,onChange:f,showLabels:_=!0,formatLabel:M,valuePlacement:N="none",label:z,error:V,helperText:H,required:g,disabled:k,readOnly:K,loading:ee,size:X="md",id:S,className:v,style:I,accessMode:j,showKeyboardHints:A,labelPlacement:Y,errorPlacement:b,labelWidth:h,controlWidth:C})=>{const w=F.rl(j,S);if(w==="hidden")return null;(w==="disabled"||w==="readOnly")&&(k=!0);const{t:O}=F.ue(),L=F.Os(S),x=a.useRef(null),p=a.useMemo(()=>[F.yl.increment,F.yl.decrement,F.yl.first,F.yl.last,{key:"Tab",description:O("shortcuts.switchThumb","Switch thumb")}],[O]),R=c=>(c-n)/(t-n)*100,y=c=>M?M(c):String(c),u=c=>{const l=Math.round(c/i)*i;return Math.max(n,Math.min(t,l))},s=a.useCallback((c,l)=>{c.preventDefault();const o=x.current;if(!o||k)return;const E=te=>{const q=o.getBoundingClientRect(),$=Math.max(0,Math.min(1,(te.clientX-q.left)/q.width)),P=u(n+$*(t-n));l==="start"?f(Math.min(P,d),d):f(r,Math.max(P,r))},J=()=>{document.removeEventListener("pointermove",E),document.removeEventListener("pointerup",J)};document.addEventListener("pointermove",E),document.addEventListener("pointerup",J)},[n,t,i,r,d,f,k]);return e.jsxs("div",{className:`nice-field nice-field--${X} nice-field--rangeslider ${Y==="left"?"nice-field--label-left":""} ${b==="right"?"nice-field--error-right":""} ${V?"nice-field--error":""} ${ee?"nice-field--loading":""} ${v||""}`,style:{...I,...h!=null&&{"--nice-field-label-width":typeof h=="number"?`${h}px`:h},...C!=null&&{"--nice-field-control-width":typeof C=="number"?`${C}px`:C}},"aria-busy":ee||void 0,children:[z&&e.jsxs("label",{className:"nice-field__label nice-field__label--with-value",htmlFor:L,children:[e.jsxs("span",{className:"nice-field__label-text",children:[z,g&&e.jsx("span",{className:"nice-field__required",children:"*"}),A&&e.jsx(F.zr,{shortcuts:p,size:"sm"})]}),N==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[y(r)," – ",y(d)]})]}),e.jsxs("div",{className:"nice-field__control",children:[N==="right"&&!z&&e.jsxs("span",{className:"nice-range-slider__value",children:[y(r)," – ",y(d)]}),e.jsxs("div",{className:"nice-range-slider__stack",children:[e.jsxs("div",{className:`nice-range-slider ${_?"nice-range-slider--with-labels":""} ${z?"nice-range-slider--has-field-label":""}`,ref:x,children:[e.jsx("div",{className:"nice-range-slider__track",children:e.jsx("div",{className:"nice-range-slider__fill",style:{left:`${R(r)}%`,width:`${R(d)-R(r)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${R(r)}%`},onPointerDown:c=>K?void 0:s(c,"start"),role:"slider","aria-valuemin":n,"aria-valuemax":d,"aria-valuenow":r,tabIndex:k?-1:0,id:L}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${R(d)}%`},onPointerDown:c=>K?void 0:s(c,"end"),role:"slider","aria-valuemin":r,"aria-valuemax":t,"aria-valuenow":d,tabIndex:k?-1:0})]}),_&&e.jsxs("div",{className:"nice-range-slider__values",children:[e.jsx("span",{className:"nice-range-slider__values-start",style:{left:`${R(r)}%`},children:y(r)}),e.jsx("span",{className:"nice-range-slider__values-end",style:{left:`${R(d)}%`},children:y(d)})]}),N==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[y(r)," – ",y(d)]})]}),ee&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),b==="right"&&V&&e.jsx("div",{className:"nice-field__error",role:"alert",children:V}),b==="right"&&!V&&H&&e.jsx("div",{className:"nice-field__helper",children:H})]}),b!=="right"&&V&&e.jsx("div",{className:"nice-field__error",role:"alert",children:V}),b!=="right"&&!V&&H&&e.jsx("div",{className:"nice-field__helper",children:H})]})},Xn=({displayValue:n,placeholder:t,clearable:i,children:r,onClear:d,open:f,onOpenChange:_,dropdownWidth:M,label:N,error:z,helperText:V,required:H,disabled:g,size:k="md",id:K,className:ee,style:X,accessMode:S,showKeyboardHints:v,displayStyle:I})=>{F.Cs("input",I),F.zs("input",I);const j=F.rl(S,K);if(j==="hidden")return null;(j==="disabled"||j==="readOnly")&&(g=!0);const A=F.Os(K),{t:Y}=F.ue(),[b,h]=a.useState(!1),C=a.useRef(null),w=f??b,O=a.useMemo(()=>[{key:"Enter",description:Y("shortcuts.openDropdown","Open dropdown")},F.yl.cancel],[Y]),L=x=>{_?_(x):h(x)};return F.Is(C,()=>L(!1)),e.jsxs("div",{className:`nice-field nice-field--${k} ${z?"nice-field--error":""} ${ee||""}`,style:X,ref:C,children:[N&&e.jsxs("label",{className:"nice-field__label",htmlFor:A,children:[N,H&&e.jsx("span",{className:"nice-field__required",children:"*"}),v&&e.jsx(F.zr,{shortcuts:O,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",children:[e.jsxs("button",{type:"button",id:A,className:"nice-select__trigger",onClick:()=>!g&&L(!w),disabled:g,children:[e.jsx("span",{children:n||t||Y("controls.select","Select...")}),e.jsx("span",{className:"nice-select__arrow",children:"▾"})]}),i&&n&&!g&&e.jsx("button",{type:"button",className:"nice-field__clear",onClick:()=>d==null?void 0:d(),"aria-label":Y("controls.clear","Clear"),children:"✕"})]}),w&&e.jsx("div",{className:"nice-dropdown",style:{width:M},children:r}),z&&e.jsx("div",{className:"nice-field__error",children:z}),V&&!z&&e.jsx("div",{className:"nice-field__hint",children:V})]})};function Rt(n){const t=n.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")?!0:!(t.startsWith("javascript:")||t.startsWith("vbscript:")||t.startsWith("data:text"))}const qn=["bold","italic","underline","strikethrough","h1","h2","h3","ul","ol","blockquote","hr","link","unlink","image","table","code","alignLeft","alignCenter","alignRight","fontSize","fontColor","undo","redo","clear","findReplace","emoji","source","fullscreen","markdown"],je=({d:n,viewBox:t="0 0 24 24"})=>e.jsx("svg",{width:"16",height:"16",viewBox:t,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:n})}),Yn={bold:e.jsx("strong",{style:{fontFamily:"serif"},children:"B"}),italic:e.jsx("em",{style:{fontFamily:"serif"},children:"I"}),underline:e.jsx("span",{style:{textDecoration:"underline"},children:"U"}),strikethrough:e.jsx("span",{style:{textDecoration:"line-through"},children:"S"}),h1:"H1",h2:"H2",h3:"H3",ul:e.jsx(je,{d:"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"}),ol:e.jsx(je,{d:"M10 6h11M10 12h11M10 18h11M4 6h1v4M4 10h2M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"}),link:e.jsx(je,{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}),unlink:e.jsx(je,{d:"M18.84 12.25l1.72-1.71a5 5 0 0 0-7.07-7.07L11 5.78M3 3l18 18M9 15l3-3M14 11l3 3M14 21l-1.72-1.72a5 5 0 0 1-7.07-7.07L7 10.49"}),undo:e.jsx(je,{d:"M3 7v6h6M3 13a9 9 0 1 0 3-7.7L3 13"}),redo:e.jsx(je,{d:"M21 7v6h-6M21 13a9 9 0 1 1-3-7.7L21 13"}),clear:e.jsx(je,{d:"M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),table:e.jsx(je,{d:"M3 3h18v18H3zM3 9h18M3 15h18M9 3v18M15 3v18"}),image:e.jsx(je,{d:"M3 3h18v18H3zM3 16l5-5 4 4 3-3 6 6M9 9a2 2 0 1 1-4 0 2 2 0 0 1 4 0z"}),code:e.jsx(je,{d:"M16 18l6-6-6-6M8 6l-6 6 6 6"}),markdown:"MD",blockquote:e.jsx(je,{d:"M3 21c3-3 3-9 0-12M21 21c-3-3-3-9 0-12M9 7h6v6H9zM15 7h6v6h-6z"}),hr:e.jsx(je,{d:"M5 12h14"}),subscript:"X₂",superscript:"X²",indent:e.jsx(je,{d:"M3 8l4 4-4 4M7 6h14M7 12h14M3 18h18"}),outdent:e.jsx(je,{d:"M7 8l-4 4 4 4M21 6H3M21 12H7M21 18H3"}),alignLeft:e.jsx(je,{d:"M3 6h18M3 12h12M3 18h18"}),alignCenter:e.jsx(je,{d:"M3 6h18M6 12h12M3 18h18"}),alignRight:e.jsx(je,{d:"M3 6h18M9 12h12M3 18h18"}),alignJustify:e.jsx(je,{d:"M3 6h18M3 12h18M3 18h18"}),fullscreen:e.jsx(je,{d:"M3 9V3h6M21 9V3h-6M3 15v6h6M21 15v6h-6"}),removeFormat:e.jsx(je,{d:"M4 7V4h16v3M5 20h6M13 4 8 20"}),print:e.jsx(je,{d:"M6 9V2h12v7M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2M6 14h12v8H6z"}),source:e.jsx(je,{d:"M16 18l6-6-6-6M8 6l-6 6 6 6"}),emoji:e.jsx(je,{d:"M12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20zM8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01"}),findReplace:e.jsx(je,{d:"M11 19a8 8 0 1 1 0-16 8 8 0 0 1 0 16zM21 21l-4.35-4.35"}),fontSize:e.jsx(je,{d:"M4 7V4h16v3M9 20h6M12 4v16"}),fontColor:e.jsx(je,{d:"M4 21h16M5 17l7-12 7 12M8 13h8"})},Jn=[{value:"1",label:"8pt"},{value:"2",label:"10pt"},{value:"3",label:"12pt"},{value:"4",label:"14pt"},{value:"5",label:"18pt"},{value:"6",label:"24pt"},{value:"7",label:"36pt"}],Wn=[{label:"Faces",emojis:["??","??","??","??","??","??","??","??","??","??","??","??"]},{label:"Hands",emojis:["??","??","??","??","??","??","??","??","??","??"]},{label:"Symbols",emojis:["??","?","??","?","?","?","??","??","??","??","??","??"]},{label:"Arrows",emojis:["??","??","??","??","??","??","??","??","??","?"]}];function Qn(n){let t=n;return t=t.replace(/<h1[^>]*>(.*?)<\/h1>/gi,`# $1
|
|
2
|
+
`),t=t.replace(/<h2[^>]*>(.*?)<\/h2>/gi,`## $1
|
|
3
|
+
`),t=t.replace(/<h3[^>]*>(.*?)<\/h3>/gi,`### $1
|
|
4
|
+
`),t=t.replace(/<strong[^>]*>(.*?)<\/strong>/gi,"**$1**"),t=t.replace(/<b[^>]*>(.*?)<\/b>/gi,"**$1**"),t=t.replace(/<em[^>]*>(.*?)<\/em>/gi,"*$1*"),t=t.replace(/<i[^>]*>(.*?)<\/i>/gi,"*$1*"),t=t.replace(/<code[^>]*>(.*?)<\/code>/gi,"`$1`"),t=t.replace(/<pre[^>]*>(.*?)<\/pre>/gis,"```\n$1\n```\n"),t=t.replace(/<br\s*\/?>/gi,`
|
|
5
|
+
`),t=t.replace(/<li[^>]*>(.*?)<\/li>/gi,`- $1
|
|
6
|
+
`),t=t.replace(/<\/?(?:ul|ol|p|div)[^>]*>/gi,`
|
|
7
|
+
`),t=t.replace(/<[^>]+>/g,""),t=t.replace(/\n{3,}/g,`
|
|
8
|
+
|
|
9
|
+
`),t.trim()}function Gn(n){let t=n;return t=t.replace(/^### (.+)$/gm,"<h3>$1</h3>"),t=t.replace(/^## (.+)$/gm,"<h2>$1</h2>"),t=t.replace(/^# (.+)$/gm,"<h1>$1</h1>"),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/`([^`]+)`/g,"<code>$1</code>"),t=t.replace(/```\n?([\s\S]*?)\n?```/g,"<pre>$1</pre>"),t=t.replace(/^- (.+)$/gm,"<li>$1</li>"),t=t.replace(/(<li>.*<\/li>)/gs,"<ul>$1</ul>"),t=t.replace(/\n/g,"<br>"),t}const vt=({value:n,onChange:t,placeholder:i,height:r=200,toolbar:d=qn,readOnly:f,onImageUpload:_,mentionTrigger:M,mentionSuggestions:N,onMentionSearch:z,onFileDrop:V,pasteCleanup:H=!0,maxLength:g=0,showWordCount:k=!1,templates:K,label:ee,error:X,helperText:S,required:v,disabled:I,size:j="md",id:A,className:Y,style:b,accessMode:h})=>{const C=F.rl(h,A);if(C==="hidden")return null;C==="disabled"&&(I=!0),C==="readOnly"&&(f=!0);const w=F.Os(A),O=a.useRef(null),L=a.useRef(null),x=a.useRef(null),[p,R]=a.useState(!1),[y,u]=a.useState(""),[s,c]=a.useState(!1),[l,o]=a.useState(""),[E,J]=a.useState(!1),[te,q]=a.useState(""),[$,P]=a.useState(0),[W,le]=a.useState(!1),[re,pe]=a.useState("#000000"),[me,Ne]=a.useState("#ffff00"),[ne,de]=a.useState(0),[ue,ve]=a.useState(0),[se,D]=a.useState(!1),[T,ae]=a.useState(""),[Q,B]=a.useState(""),[ie,oe]=a.useState(!1),[ke,ge]=a.useState(!1),ye=a.useCallback((U,ce)=>{var _e,be,we;if(f||I)return;const he=O.current;if(he){if(U==="markdown"){if(!p)u(Qn(n)),R(!0),c(!1);else{const xe=Gn(y);t(xe),R(!1)}return}if(U==="source"){s?(t(l),c(!1)):(o(n),c(!0),R(!1));return}if(U==="fullscreen"){le(xe=>!xe);return}if(U==="emoji"){oe(xe=>!xe);return}if(U==="findReplace"){D(xe=>!xe);return}if(U==="image"){if(_)(_e=L.current)==null||_e.click();else{const xe=prompt("Image URL:");xe&&Rt(xe)&&(he.focus(),document.execCommand("insertImage",!1,xe),t(F.Ts(he.innerHTML)))}return}switch(he.focus(),U){case"bold":document.execCommand("bold");break;case"italic":document.execCommand("italic");break;case"underline":document.execCommand("underline");break;case"strikethrough":document.execCommand("strikeThrough");break;case"h1":document.execCommand("formatBlock",!1,"h1");break;case"h2":document.execCommand("formatBlock",!1,"h2");break;case"h3":document.execCommand("formatBlock",!1,"h3");break;case"ul":document.execCommand("insertUnorderedList");break;case"ol":document.execCommand("insertOrderedList");break;case"blockquote":document.execCommand("formatBlock",!1,"blockquote");break;case"hr":document.execCommand("insertHorizontalRule");break;case"subscript":document.execCommand("subscript");break;case"superscript":document.execCommand("superscript");break;case"indent":document.execCommand("indent");break;case"outdent":document.execCommand("outdent");break;case"alignLeft":document.execCommand("justifyLeft");break;case"alignCenter":document.execCommand("justifyCenter");break;case"alignRight":document.execCommand("justifyRight");break;case"alignJustify":document.execCommand("justifyFull");break;case"removeFormat":document.execCommand("removeFormat");break;case"print":window.print();return;case"link":{const xe=prompt("URL:");xe&&Rt(xe)&&document.execCommand("createLink",!1,xe);break}case"unlink":document.execCommand("unlink");break;case"undo":document.execCommand("undo");break;case"redo":document.execCommand("redo");break;case"clear":document.execCommand("removeFormat");break;case"fontSize":{ce&&document.execCommand("fontSize",!1,ce);break}case"fontColor":{ce&&document.execCommand("foreColor",!1,ce);break}case"bgColor":{ce&&document.execCommand("hiliteColor",!1,ce);break}case"table":{document.execCommand("insertHTML",!1,'<table class="nice-htmleditor__table"><thead><tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td> </td><td> </td><td> </td></tr><tr><td> </td><td> </td><td> </td></tr></tbody></table><p> </p>');break}case"code":{const xe=((be=window.getSelection())==null?void 0:be.toString())||"";xe.includes(`
|
|
10
|
+
`)||xe.length>60?document.execCommand("insertHTML",!1,`<pre class="nice-htmleditor__code-block">${xe||"// code"}</pre>`):document.execCommand("insertHTML",!1,`<code>${xe||"code"}</code>`);break}}t(F.Ts(he.innerHTML)),de(((we=he.textContent)==null?void 0:we.length)??0)}},[t,f,I,p,y,n,_,s,l]),Me=a.useCallback(async U=>{var be;const ce=(be=U.target.files)==null?void 0:be[0];if(!ce||!_)return;const he=await _(ce),_e=O.current;_e&&he&&(_e.focus(),document.execCommand("insertImage",!1,he),t(_e.innerHTML)),U.target.value=""},[_,t]),rt=a.useCallback(()=>{var he;const U=O.current;if(!U)return;const ce=((he=U.textContent)==null?void 0:he.length)??0;if(g>0&&ce>g&&(U.textContent=(U.textContent??"").slice(0,g)),de(ce),ve((U.textContent??"").trim().split(/\s+/).filter(Boolean).length),t(U.innerHTML),M){const _e=window.getSelection();if(_e&&_e.rangeCount>0){const be=_e.getRangeAt(0),we=be.startContainer;if(we.nodeType===Node.TEXT_NODE){const xe=we.textContent||"",Ie=be.startOffset,Te=xe.slice(0,Ie),Re=Te.lastIndexOf(M);if(Re>=0&&(Re===0||/\s/.test(Te[Re-1]))){const Ae=Te.slice(Re+M.length);if(!/\s/.test(Ae)){J(!0),q(Ae),P(0),z==null||z(Ae);return}}}}J(!1)}},[t,M,z]),De=(N==null?void 0:N.filter(U=>U.label.toLowerCase().includes(te.toLowerCase())).slice(0,8))??[],He=a.useCallback(U=>{var we;const ce=O.current;if(!ce)return;const he=window.getSelection();if(!he||he.rangeCount===0)return;const _e=he.getRangeAt(0),be=_e.startContainer;if(be.nodeType===Node.TEXT_NODE&&M){const xe=be.textContent||"",Ie=_e.startOffset,Te=xe.slice(0,Ie).lastIndexOf(M);if(Te>=0){const Re=xe.slice(0,Te),Ae=xe.slice(Ie),Qe=`<span class="nice-htmleditor__mention" data-mention="${U.key}" contenteditable="false">${M}${U.label}</span> `;be.textContent=Re;const Oe=document.createRange();Oe.setStartAfter(be),Oe.collapse(!0);const Ge=Oe.createContextualFragment(Qe+Ae);(we=be.parentNode)==null||we.insertBefore(Ge,be.nextSibling),he.collapseToEnd(),t(ce.innerHTML)}}J(!1)},[M,t]),lt=a.useCallback(U=>{if(E&&De.length>0){U.key==="ArrowDown"?(U.preventDefault(),P(ce=>Math.min(ce+1,De.length-1))):U.key==="ArrowUp"?(U.preventDefault(),P(ce=>Math.max(ce-1,0))):U.key==="Enter"?(U.preventDefault(),He(De[$])):U.key==="Escape"&&J(!1);return}(U.ctrlKey||U.metaKey)&&U.key==="b"?(U.preventDefault(),ye("bold")):(U.ctrlKey||U.metaKey)&&U.key==="i"?(U.preventDefault(),ye("italic")):(U.ctrlKey||U.metaKey)&&U.key==="u"?(U.preventDefault(),ye("underline")):(U.ctrlKey||U.metaKey)&&U.key==="f"?(U.preventDefault(),D(ce=>!ce)):(U.ctrlKey||U.metaKey)&&U.key==="z"&&!U.shiftKey?(U.preventDefault(),ye("undo")):(U.ctrlKey||U.metaKey)&&(U.key==="y"||U.key==="z"&&U.shiftKey)&&(U.preventDefault(),ye("redo"))},[E,De,$,He,ye]),st=a.useCallback(U=>{var be;if(!H)return;U.preventDefault();const ce=U.clipboardData.getData("text/html"),he=U.clipboardData.getData("text/plain");if(ce){const we=ce.replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<script[\s\S]*?<\/script>/gi,"").replace(/class="[^"]*"/gi,"").replace(/style="[^"]*"/gi,"").replace(/<o:[^>]*>[\s\S]*?<\/o:[^>]*>/gi,"").replace(/<!--[\s\S]*?-->/g,"").replace(/<\/?(?:xml|meta|link|font|span)[^>]*>/gi,"");document.execCommand("insertHTML",!1,we)}else he&&document.execCommand("insertText",!1,he);const _e=O.current;_e&&(t(_e.innerHTML),de(((be=_e.textContent)==null?void 0:be.length)??0))},[H,t]),ot=a.useCallback(async U=>{if(!V)return;U.preventDefault();const ce=Array.from(U.dataTransfer.files);if(ce.length===0)return;const he=await V(ce),_e=O.current;if(_e){_e.focus();for(const be of he)if(/\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i.test(be)||be.startsWith("data:image/"))document.execCommand("insertImage",!1,be);else{const we=`<a href="${be}">${be.split("/").pop()??be}</a>`;document.execCommand("insertHTML",!1,we)}t(_e.innerHTML)}},[V,t]),ct=a.useCallback(U=>{V&&U.preventDefault()},[V]),Ke=a.useCallback(U=>{var we;const ce=O.current;if(!ce||!T)return;const he=ce.textContent??"",_e=T.toLowerCase(),be=he.toLowerCase();(U===1?be.indexOf(_e):be.lastIndexOf(_e))!==-1&&(ce.focus(),(we=window.find)==null||we.call(window,T))},[T]),dt=a.useCallback(()=>{const U=O.current;!U||!T||(U.innerHTML=U.innerHTML.split(T).join(Q),t(U.innerHTML))},[T,Q,t]),ut=a.useCallback(()=>{if(!T)return;const U=n.split(T).join(Q);t(U);const ce=O.current;ce&&(ce.innerHTML=U)},[T,Q,n,t]),Le=a.useCallback(U=>{const ce=O.current;ce&&(ce.focus(),document.execCommand("insertText",!1,U),t(ce.innerHTML),oe(!1))},[t]),$e=a.useCallback(U=>{const ce=O.current;ce&&(ce.focus(),document.execCommand("insertHTML",!1,U),t(ce.innerHTML),ge(!1))},[t]),Ee=a.useCallback(U=>{const ce=I||f;return U==="fontSize"?e.jsx(F.Je,{size:"sm",value:"",onChange:he=>ye("fontSize",String(he)),disabled:ce,placeholder:"Size",options:Jn.map(he=>({value:he.value,label:he.label})),style:{minWidth:70,maxWidth:80}},U):U==="fontColor"?e.jsx(F.an,{value:re,onChange:he=>{pe(he),ye("fontColor",he)},disabled:ce,size:"sm",label:"",title:"Text color"},U):U==="bgColor"?e.jsx(F.an,{value:me,onChange:he=>{Ne(he),ye("bgColor",he)},disabled:ce,size:"sm",label:"",title:"Highlight color"},U):e.jsx(F.on,{size:"sm",variant:U==="markdown"&&p||U==="fullscreen"&&W||U==="source"&&s||U==="findReplace"&&se||U==="emoji"&&ie?"primary":"ghost",onClick:()=>ye(U),title:U,disabled:ce,children:Yn[U]||U},U)},[I,f,ye,p,W,re,me,s,se,ie]);return e.jsxs("div",{className:`nice-field nice-field--${j} ${X?"nice-field--error":""} ${Y||""}`,style:b,children:[ee&&e.jsxs("label",{className:"nice-field__label",htmlFor:w,children:[ee,v&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{ref:x,className:`nice-htmleditor${W?" nice-htmleditor--fullscreen":""}`,children:[e.jsxs("div",{className:"nice-htmleditor__toolbar",style:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center"},children:[d.map(Ee),K&&K.length>0&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(F.on,{size:"sm",variant:ke?"primary":"ghost",onClick:()=>ge(U=>!U),title:"Insert template",children:"??"}),ke&&e.jsx("ul",{style:{position:"absolute",top:"100%",right:0,zIndex:200,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,.12)",listStyle:"none",margin:0,padding:4,minWidth:160,maxHeight:200,overflow:"auto"},children:K.map((U,ce)=>e.jsx("li",{style:{padding:"6px 10px",cursor:"pointer",borderRadius:4},onMouseDown:he=>{he.preventDefault(),$e(U.html)},children:U.label},ce))})]})]}),se&&e.jsxs("div",{className:"nice-htmleditor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--bg-secondary, #f8f9fa)",borderBottom:"1px solid var(--border-color, #ddd)",fontSize:"0.875em"},children:[e.jsx("input",{type:"text",placeholder:"Find...",value:T,onChange:U=>ae(U.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--border-color, #ccc)",borderRadius:4,background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)"}}),e.jsx("input",{type:"text",placeholder:"Replace...",value:Q,onChange:U=>B(U.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--border-color, #ccc)",borderRadius:4,background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)"}}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>Ke(1),title:"Find next",children:"?"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>Ke(-1),title:"Find previous",children:"?"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:dt,disabled:I||f,children:"Replace"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:ut,disabled:I||f,children:"All"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>D(!1),children:"?"})]}),ie&&e.jsx("div",{className:"nice-htmleditor__emoji-picker",style:{padding:8,background:"var(--bg-primary, #fff)",borderBottom:"1px solid var(--border-color, #ddd)",maxHeight:180,overflowY:"auto"},children:Wn.map(U=>e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"0.7em",fontWeight:600,color:"var(--text-muted, #999)",padding:"4px 0"},children:U.label}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:2},children:U.emojis.map(ce=>e.jsx("span",{style:{cursor:"pointer",fontSize:"1.2em",padding:2,borderRadius:4},onClick:()=>Le(ce),title:ce,children:ce},ce))})]},U.label))}),e.jsx("input",{ref:L,type:"file",accept:"image/*",style:{display:"none"},onChange:Me}),s?e.jsx("textarea",{className:"nice-htmleditor__source",value:l,onChange:U=>o(U.target.value),style:{minHeight:r,width:"100%",fontFamily:"monospace",resize:"vertical",whiteSpace:"pre",fontSize:"0.85em",background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:I||f}):p?e.jsx("textarea",{className:"nice-htmleditor__markdown",value:y,onChange:U=>u(U.target.value),style:{minHeight:r,width:"100%",fontFamily:"monospace",resize:"vertical",background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:I||f}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:O,id:w,className:"nice-htmleditor__content",contentEditable:!I&&!f,dangerouslySetInnerHTML:{__html:n},onInput:rt,onKeyDown:lt,onPaste:st,onDrop:ot,onDragOver:ct,style:{minHeight:r},"data-placeholder":i,role:"textbox","aria-multiline":"true",suppressContentEditableWarning:!0}),E&&De.length>0&&e.jsx("ul",{className:"nice-htmleditor__mention-list",children:De.map((U,ce)=>e.jsx("li",{className:`nice-htmleditor__mention-item ${ce===$?"nice-htmleditor__mention-item--active":""}`,onMouseDown:he=>{he.preventDefault(),He(U)},children:U.label},U.key))})]}),e.jsxs("div",{className:"nice-htmleditor__statusbar",style:{display:"flex",gap:12,padding:"2px 8px",fontSize:"0.75em",color:"var(--text-muted, #666)",borderTop:"1px solid var(--border-color, #eee)"},children:[g>0&&e.jsxs("span",{children:[ne," / ",g]}),k&&e.jsxs("span",{children:[ue," words"]}),k&&e.jsxs("span",{children:[ne," chars"]}),s&&e.jsx("span",{style:{fontWeight:600},children:"HTML Source"}),p&&e.jsx("span",{style:{fontWeight:600},children:"Markdown"})]})]}),X&&e.jsx("div",{className:"nice-field__error",children:X}),S&&!X&&e.jsx("div",{className:"nice-field__hint",children:S})]})},Zn=Object.freeze(Object.defineProperty({__proto__:null,NiceHtmlEditor:vt},Symbol.toStringTag,{value:"Module"})),ea=[{code:"en",label:"English"},{code:"es",label:"Spanish"},{code:"fr",label:"French"},{code:"de",label:"German"},{code:"it",label:"Italian"},{code:"pt",label:"Portuguese"},{code:"pl",label:"Polish"},{code:"ru",label:"Russian"},{code:"zh",label:"Chinese"},{code:"ja",label:"Japanese"},{code:"ko",label:"Korean"},{code:"ar",label:"Arabic"}],ta=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}];a.forwardRef(function(n,t){var ve,se;const{enableAI:i=!0,aiModel:r,enableImprove:d=!0,enableTranslate:f=!0,enableGenerate:_=!0,toolbar:M,languages:N=ea,textStyles:z=ta,onImprove:V,onTranslate:H,onGenerate:g,showAIToolbar:k=!0,value:K,onChange:ee,...X}=n,S=a.useRef(null),[v,I]=a.useState(!1),[j,A]=a.useState(!1),[Y,b]=a.useState(!1),[h,C]=a.useState(""),[w,O]=a.useState(""),[L,x]=a.useState("professional"),[p,R]=a.useState(""),[y,u]=a.useState(((ve=N[0])==null?void 0:ve.code)||"en"),[s,c]=a.useState(""),[l,o]=a.useState(""),{t:E}=F.ue(),J=F.me(),{improveText:te,translate:q,generateHtml:$,isLoading:P}=F.kd(),W=i&&J.isConfigured,le=a.useCallback(()=>{const D=window.getSelection();return D&&D.toString().trim()?D.toString():""},[]),re=a.useCallback(D=>{const T=window.getSelection();if(T&&T.rangeCount>0){const ae=T.getRangeAt(0);ae.deleteContents();const Q=document.createElement("div");Q.innerHTML=D;const B=document.createDocumentFragment();for(;Q.firstChild;)B.appendChild(Q.firstChild);if(ae.insertNode(B),S.current){const ie=S.current.innerHTML;ee(ie)}}},[ee]),pe=a.useCallback(async(D="professional")=>{if(!W||!d)return"";const T=le();if(!T)return"";C(T),x(D),I(!0),O("");try{const ae=await te(T,D);return O(ae),V==null||V(T,ae,D),ae}catch{return O(E("htmlEditorAI.improveFailed","Failed to improve text")),""}},[W,d,le,te,V,E]),me=a.useCallback(async D=>{var ae;if(!W||!f)return"";const T=le();if(!T)return"";C(T),u(D),A(!0),R("");try{const Q=((ae=N.find(ie=>ie.code===D))==null?void 0:ae.label)||D,B=await q(T,Q);return R(B),H==null||H(T,B,D),B}catch{return R(E("htmlEditorAI.translateFailed","Failed to translate text")),""}},[W,f,le,q,N,H,E]),Ne=a.useCallback(async D=>{if(!W||!_||!D.trim())return"";c(D),o("");try{const T=await $(D);return o(T),g==null||g(D,T),T}catch{return o(E("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[W,_,$,g,E]),ne=a.useCallback(()=>{w&&re(w),I(!1),O("")},[w,re]),de=a.useCallback(()=>{p&&re(p),A(!1),R("")},[p,re]),ue=a.useCallback(()=>{if(l&&S.current){document.execCommand("insertHTML",!1,l);const D=S.current.innerHTML;ee(D)}b(!1),o(""),c("")},[l,ee]);return a.useImperativeHandle(t,()=>({getEditor:()=>S.current,focus:()=>{var D;return(D=S.current)==null?void 0:D.focus()},getValue:()=>{var D;return((D=S.current)==null?void 0:D.innerHTML)||""},setValue:D=>{S.current&&(S.current.innerHTML=D,ee(D))},getSelection:le,insertHtml:D=>{document.execCommand("insertHTML",!1,D),S.current&&ee(S.current.innerHTML)},improveSelection:pe,translateSelection:me,generateHtml:Ne})),a.useCallback(D=>{S.current=D},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":n["data-testid"],children:[k&&W&&e.jsxs("div",{className:"nice-html-editor-ai__toolbar",children:[e.jsxs("div",{className:"nice-html-editor-ai__toolbar-left",children:[e.jsx("span",{className:"nice-html-editor-ai__badge",children:"AI"}),P&&e.jsx("span",{className:"nice-html-editor-ai__loading",children:E("htmlEditorAI.processing","Processing...")})]}),e.jsxs("div",{className:"nice-html-editor-ai__toolbar-right",children:[d&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>pe(),disabled:P,title:E("htmlEditorAI.improveText","Improve selected text"),children:["✨ ",E("htmlEditorAI.improve","Improve")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu",children:z.map(({style:D,label:T})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>pe(D),children:T},D))})]}),f&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",disabled:P,title:E("htmlEditorAI.translateText","Translate selected text"),children:["🌐 ",E("htmlEditorAI.translate","Translate")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu nice-html-editor-ai__dropdown-menu--languages",children:N.map(({code:D,label:T})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>me(D),children:T},D))})]}),_&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>b(!0),disabled:P,title:E("htmlEditorAI.generateHtml","Generate HTML from description"),children:["⚡ ",E("htmlEditorAI.generate","Generate")]})]})]}),e.jsx("div",{className:"nice-html-editor-ai__editor-wrapper",children:e.jsx(vt,{value:K,onChange:ee,toolbar:M,...X})}),v&&e.jsxs("div",{className:"nice-html-editor-ai__panel",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["✨ ",E("htmlEditorAI.improveText","Improve Text")]}),e.jsx("div",{className:"nice-html-editor-ai__style-selector",children:z.map(({style:D,label:T})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${L===D?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{x(D),pe(D)},children:T},D))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>I(!1),children:"✕"})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:P?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:E("htmlEditorAI.improving","Improving text...")}):e.jsxs("div",{className:"nice-html-editor-ai__comparison",children:[e.jsxs("div",{className:"nice-html-editor-ai__text-block",children:[e.jsx("h5",{children:E("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:h})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--improved",children:[e.jsx("h5",{children:E("htmlEditorAI.improved","Improved")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:w})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ne,disabled:!w||P,children:["✓ ",E("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{I(!1),O("")},children:E("htmlEditorAI.cancel","Cancel")})]})]}),j&&e.jsxs("div",{className:"nice-html-editor-ai__panel",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["🌐 ",E("htmlEditorAI.translateText","Translate Text")]}),e.jsx("div",{className:"nice-html-editor-ai__language-selector",children:e.jsx("select",{value:y,onChange:D=>{u(D.target.value),me(D.target.value)},className:"nice-html-editor-ai__language-select",children:N.map(({code:D,label:T})=>e.jsx("option",{value:D,children:T},D))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>A(!1),children:"✕"})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:P?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:E("htmlEditorAI.translating","Translating...")}):e.jsxs("div",{className:"nice-html-editor-ai__comparison",children:[e.jsxs("div",{className:"nice-html-editor-ai__text-block",children:[e.jsx("h5",{children:E("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:h})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:((se=N.find(D=>D.code===y))==null?void 0:se.label)||y}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:p})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:de,disabled:!p||P,children:["✓ ",E("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{A(!1),R("")},children:E("htmlEditorAI.cancel","Cancel")})]})]}),Y&&e.jsxs("div",{className:"nice-html-editor-ai__panel nice-html-editor-ai__panel--generate",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["⚡ ",E("htmlEditorAI.generateHtml","Generate HTML")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>{b(!1),o(""),c("")},children:"✕"})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-body",children:[e.jsxs("div",{className:"nice-html-editor-ai__generate-input",children:[e.jsx("textarea",{placeholder:E("htmlEditorAI.generatePlaceholder",'Describe what you want to create (e.g., "A pricing table with 3 tiers", "A contact form with name, email, and message")'),value:s,onChange:D=>c(D.target.value),className:"nice-html-editor-ai__generate-textarea",rows:3}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__generate-btn",onClick:()=>Ne(s),disabled:P||!s.trim(),children:P?E("htmlEditorAI.generating","Generating..."):E("htmlEditorAI.generate","Generate")})]}),l&&e.jsxs("div",{className:"nice-html-editor-ai__generate-result",children:[e.jsx("h5",{children:E("htmlEditorAI.preview","Preview")}),e.jsx("div",{className:"nice-html-editor-ai__preview",dangerouslySetInnerHTML:{__html:l}}),e.jsx("h5",{children:E("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:l})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ue,disabled:!l||P,children:["✓ ",E("htmlEditorAI.insert","Insert")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{b(!1),o(""),c("")},children:E("htmlEditorAI.cancel","Cancel")})]})]})]})});const nn=a.forwardRef(({length:n=6,value:t="",onChange:i,masked:r=!1,onComplete:d,label:f,helperText:_,error:M,required:N,disabled:z,readOnly:V,size:H="md",name:g,id:k,className:K,style:ee,autoFocus:X,labelPlacement:S,errorPlacement:v,labelWidth:I,controlWidth:j,loading:A,cellWidth:Y,...b},h)=>{const C=F.Os(k),w=a.useRef([]),O=t.padEnd(n,"").slice(0,n).split(""),L=a.useCallback(u=>{var c;const s=Math.max(0,Math.min(n-1,u));(c=w.current[s])==null||c.focus()},[n]),x=a.useCallback(u=>{const s=u.join("");i==null||i(s),s.length===n&&s.indexOf("")===-1&&/^\d+$/.test(s)&&(d==null||d(s))},[i,d,n]),p=a.useCallback((u,s)=>{const c=s.target.value.replace(/\D/g,"").slice(-1);if(!c)return;const l=[...O];l[u]=c,x(l),L(u+1)},[O,x,L]),R=a.useCallback((u,s)=>{if(s.key==="Backspace"){s.preventDefault();const c=[...O];O[u]?(c[u]="",x(c)):u>0&&(c[u-1]="",x(c),L(u-1))}else s.key==="ArrowLeft"?(s.preventDefault(),L(u-1)):s.key==="ArrowRight"&&(s.preventDefault(),L(u+1))},[O,x,L]),y=a.useCallback(u=>{u.preventDefault();const s=u.clipboardData.getData("text").replace(/\D/g,"").slice(0,n);if(!s)return;const c=s.padEnd(n,"").slice(0,n).split("");for(let l=s.length;l<n;l++)c[l]=O[l]||"";x(c),L(Math.min(s.length,n-1))},[n,O,x,L]);return e.jsxs("div",{className:`nice-field nice-field--${H} nice-field--otp${S?` nice-field--label-${S}`:""}${v==="right"?" nice-field--error-right":""} ${A?"nice-field--loading":""} ${K||""}`,style:{...ee,...I!=null&&{"--nice-field-label-width":typeof I=="number"?`${I}px`:I},...j!=null&&{"--nice-field-control-width":typeof j=="number"?`${j}px`:j},...Y!=null&&{"--nice-otp-cell-width":typeof Y=="number"?`${Y}px`:Y}},"aria-busy":A||void 0,...b,children:[f&&e.jsx("label",{htmlFor:`${C}-0`,className:`nice-field__label ${N?"nice-field__label--required":""}`,children:f}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{ref:h,className:`nice-otp nice-otp--${H} ${M?"nice-otp--error":""} ${z?"nice-otp--disabled":""}`,onPaste:y,children:[Array.from({length:n},(u,s)=>e.jsx("input",{ref:c=>{w.current[s]=c},id:s===0?`${C}-0`:void 0,className:"nice-otp__digit",type:r?"password":"text",inputMode:"numeric",maxLength:2,value:O[s]||"",disabled:z,readOnly:V,autoFocus:X&&s===0,"aria-invalid":!!M,"aria-label":`${s+1}`,onChange:c=>p(s,c),onKeyDown:c=>R(s,c),onFocus:c=>c.target.select()},s)),g&&e.jsx("input",{type:"hidden",name:g,value:t})]}),v==="right"&&M&&e.jsx("div",{id:`${C}-error`,className:"nice-field__error",role:"alert",children:M}),v==="right"&&!M&&_&&e.jsx("div",{id:`${C}-helper`,className:"nice-field__helper",children:_}),A&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]}),v!=="right"&&M&&e.jsx("div",{id:`${C}-error`,className:"nice-field__error",role:"alert",children:M}),v!=="right"&&!M&&_&&e.jsx("div",{id:`${C}-helper`,className:"nice-field__helper",children:_})]})});nn.displayName="NiceInputOtp";const na={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160},Ze=6,Ye=135,an=405,Be=an-Ye;function bt(n,t,i,r){const d=(r-90)*(Math.PI/180);return{x:n+i*Math.cos(d),y:t+i*Math.sin(d)}}function Dt(n,t,i,r,d){const f=bt(n,t,i,r),_=bt(n,t,i,d),M=d-r>180?1:0;return`M ${f.x} ${f.y} A ${i} ${i} 0 ${M} 1 ${_.x} ${_.y}`}const rn=a.forwardRef(({value:n=0,onChange:t,min:i=0,max:r=100,step:d=1,showValue:f=!0,valueTemplate:_="{value}",label:M,helperText:N,error:z,required:V,disabled:H,readOnly:g,size:k="md",name:K,id:ee,className:X,style:S,labelPlacement:v="top",errorPlacement:I,labelWidth:j,controlWidth:A,loading:Y,isLabelCentered:b=!0,...h},C)=>{const w=F.Os(ee),O=a.useRef(!1),L=a.useRef(null),x=typeof k=="number"?k:na[k],p=x/2,R=x/2,y=(x-Ze*2)/2,u=r>i?(n-i)/(r-i):0,s=Ye+u*Be,c=a.useCallback(te=>{let q=te-Ye;q<0&&(q+=360),q>Be&&(q=q-Be<360-q?Be:0);const $=Math.max(0,Math.min(1,q/Be)),P=i+$*(r-i),W=Math.round(P/d)*d;return Math.max(i,Math.min(r,W))},[i,r,d]),l=a.useCallback(te=>{if(H||g)return;const q=L.current;if(!q)return;const $=q.getBoundingClientRect(),P=te.clientX-$.left-$.width/2,W=te.clientY-$.top-$.height/2;let le=Math.atan2(P,-W)*(180/Math.PI);le<0&&(le+=360);const re=c(le);t==null||t(re)},[c,H,g,t]);a.useEffect(()=>{const te=$=>{O.current&&l($)},q=()=>{O.current=!1};return window.addEventListener("pointermove",te),window.addEventListener("pointerup",q),()=>{window.removeEventListener("pointermove",te),window.removeEventListener("pointerup",q)}},[l]);const o=a.useCallback(te=>{if(H||g)return;let q=n;te.key==="ArrowUp"||te.key==="ArrowRight"?(te.preventDefault(),q=Math.min(r,n+d)):(te.key==="ArrowDown"||te.key==="ArrowLeft")&&(te.preventDefault(),q=Math.max(i,n-d)),q!==n&&(t==null||t(q))},[n,t,i,r,d,H,g]),E=_.replace("{value}",String(n)),J=bt(p,R,y,s);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${I||"bottom"} nice-field--${typeof k=="string"?k:"md"} ${Y?"nice-field--loading":""} ${X||""}`,style:{...S,...j!=null&&{"--nice-field-label-width":typeof j=="number"?`${j}px`:j},...A!=null&&{"--nice-field-control-width":typeof A=="number"?`${A}px`:A}},"aria-busy":Y||void 0,...h,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${v} ${b?"nice-knob-field--label-centered":""}`,children:[M&&e.jsx("label",{htmlFor:w,className:`nice-field__label ${V?"nice-field__label--required":""}`,children:M}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:te=>{L.current=te,typeof C=="function"?C(te):C&&(C.current=te)},className:`nice-knob nice-knob--${k} ${H?"nice-knob--disabled":""} ${z?"nice-knob--error":""}`,role:"slider",id:w,tabIndex:H?-1:0,"aria-valuenow":n,"aria-valuemin":i,"aria-valuemax":r,"aria-disabled":H,"aria-invalid":!!z,onPointerDown:te=>{H||g||(O.current=!0,l(te))},onKeyDown:o,children:[e.jsxs("svg",{width:x,height:x,viewBox:`0 0 ${x} ${x}`,children:[e.jsx("path",{d:Dt(p,R,y,Ye,an),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:Ze,strokeLinecap:"round"}),u>0&&e.jsx("path",{d:Dt(p,R,y,Ye,s),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:Ze,strokeLinecap:"round"}),e.jsx("circle",{cx:J.x,cy:J.y,r:Ze,fill:"var(--nice-primary, #3b82f6)"})]}),f&&e.jsx("span",{className:"nice-knob__value",children:E}),K&&e.jsx("input",{type:"hidden",name:K,value:n}),Y&&e.jsx("span",{className:"nice-knob__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]})})]}),z&&e.jsx("div",{className:"nice-field__error",role:"alert",children:z}),!z&&N&&e.jsx("div",{className:"nice-field__helper",children:N})]})});rn.displayName="NiceKnob";const ln=a.forwardRef(({value:n="",onChange:t,suggestions:i=[],onSearch:r,trigger:d="@",renderSuggestion:f,placeholder:_,rows:M=3,label:N,helperText:z,error:V,required:H,disabled:g,readOnly:k,size:K="md",name:ee,id:X,className:S,style:v,...I},j)=>{const A=F.Os(X),[Y,b]=a.useState(!1),[h,C]=a.useState(""),[w,O]=a.useState(0),[L,x]=a.useState({top:0,left:0}),p=a.useRef(null),R=a.useRef(-1),y=i.map(o=>typeof o=="string"?{key:o,label:o}:o).filter(o=>o.label.toLowerCase().includes(h.toLowerCase())),u=a.useCallback(()=>{b(!1),C(""),O(0),R.current=-1},[]),s=a.useCallback(o=>{const E=p.current;if(!E||R.current<0)return;const J=n.slice(0,R.current),te=n.slice(E.selectionStart),q=`${d}${o.label} `,$=J+q+te;t==null||t($),u(),requestAnimationFrame(()=>{const P=J.length+q.length;E.setSelectionRange(P,P),E.focus()})},[n,t,d,u]),c=a.useCallback(o=>{const E=o.target.value;t==null||t(E);const J=o.target.selectionStart,te=E.slice(0,J),q=te.lastIndexOf(d);if(q>=0){const $=q>0?te[q-1]:" ",P=te.slice(q+d.length);if(/\s/.test($)&&!/\s/.test(P)){R.current=q;const W=P;C(W),b(!0),O(0),r==null||r(W);const le=o.target,re=le.getBoundingClientRect(),pe=parseInt(getComputedStyle(le).lineHeight)||20,me=te.split(`
|
|
11
|
+
`);x({top:re.top+me.length*pe+4-le.scrollTop,left:re.left+8});return}}u()},[t,d,r,u]),l=a.useCallback(o=>{!Y||y.length===0||(o.key==="ArrowDown"?(o.preventDefault(),O(E=>(E+1)%y.length)):o.key==="ArrowUp"?(o.preventDefault(),O(E=>(E-1+y.length)%y.length)):o.key==="Enter"?(o.preventDefault(),y[w]&&s(y[w])):o.key==="Escape"&&u())},[Y,y,w,s,u]);return a.useEffect(()=>{if(!Y)return;const o=E=>{const J=p.current;J&&!J.contains(E.target)&&u()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[Y,u]),e.jsxs("div",{className:`nice-field ${S||""}`,style:v,...I,children:[N&&e.jsx("label",{htmlFor:A,className:`nice-field__label ${H?"nice-field__label--required":""}`,children:N}),e.jsxs("div",{className:`nice-mention nice-mention--${K} ${V?"nice-mention--error":""} ${g?"nice-mention--disabled":""}`,children:[e.jsx("textarea",{ref:o=>{p.current=o,typeof j=="function"?j(o):j&&(j.current=o)},id:A,name:ee,className:"nice-mention__input",value:n,onChange:c,onKeyDown:l,placeholder:_,rows:M,disabled:g,readOnly:k,"aria-invalid":!!V,"aria-describedby":V?`${A}-error`:z?`${A}-helper`:void 0,"aria-autocomplete":"list","aria-expanded":Y}),Y&&y.length>0&&e.jsx("ul",{className:"nice-mention__suggestions",role:"listbox",style:{position:"fixed",top:L.top,left:L.left},children:y.map((o,E)=>e.jsx("li",{role:"option","aria-selected":E===w,className:`nice-mention__suggestion ${E===w?"nice-mention__suggestion--active":""}`,onMouseDown:J=>{J.preventDefault(),s(o)},onMouseEnter:()=>O(E),children:f?f(o):e.jsxs(e.Fragment,{children:[o.icon&&e.jsx("span",{className:"nice-mention__suggestion-icon",children:o.icon}),e.jsx("span",{children:o.label})]})},o.key))})]}),V&&e.jsx("div",{id:`${A}-error`,className:"nice-field__error",role:"alert",children:V}),!V&&z&&e.jsx("div",{id:`${A}-helper`,className:"nice-field__helper",children:z})]})});ln.displayName="NiceMention";function aa(n){const t=[],i=r=>{for(const d of r)t.push(d),d.children&&i(d.children)};return i(n),t}function sn(n,t){const i=t.toLowerCase();return n.reduce((r,d)=>{const f=d.children?sn(d.children,t):[];return(d.label.toLowerCase().includes(i)||f.length>0)&&r.push({...d,children:f.length>0?f:d.children}),r},[])}const on=({node:n,level:t,selectedKeys:i,expandedKeys:r,onToggleExpand:d,onSelect:f,selectableLeafsOnly:_})=>{const M=n.children&&n.children.length>0,N=r.has(n.key),z=i.has(n.key),V=!M,H=!n.disabled&&(!_||V);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`nice-tree-select__node ${z?"nice-tree-select__node--selected":""} ${n.disabled?"nice-tree-select__node--disabled":""}`,style:{paddingLeft:t*16+8},onClick:()=>H&&f(n.key),role:"treeitem","aria-selected":z,"aria-expanded":M?N:void 0,"aria-disabled":n.disabled,children:[M?e.jsx("button",{type:"button",className:"nice-tree-select__toggle",onClick:g=>{g.stopPropagation(),d(n.key)},"aria-label":"Toggle",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor",style:{transform:N?"rotate(90deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M4.5 2l4 4-4 4"})})}):e.jsx("span",{style:{width:12,display:"inline-block"}}),(n.icon==null,null),e.jsx("span",{className:"nice-tree-select__node-label",children:n.label})]}),M&&N&&n.children.map(g=>e.jsx(on,{node:g,level:t+1,selectedKeys:i,expandedKeys:r,onToggleExpand:d,onSelect:f,selectableLeafsOnly:_},g.key))]})},cn=a.forwardRef(({nodes:n,value:t,onChange:i,multiple:r=!1,searchable:d=!1,placeholder:f,selectableLeafsOnly:_=!1,clearable:M=!1,label:N,helperText:z,error:V,required:H,disabled:g,readOnly:k,size:K="md",name:ee,id:X,className:S,style:v,controlWidth:I,...j},A)=>{const{t:Y}=F.ue(),b=F.Os(X),[h,C]=a.useState(!1),[w,O]=a.useState(""),[L,x]=a.useState(new Set),p=a.useRef(null);F.Is(p,()=>C(!1));const R=a.useMemo(()=>t==null?new Set:new Set(Array.isArray(t)?t:[t]),[t]),y=a.useMemo(()=>w?sn(n,w):n,[n,w]),u=a.useMemo(()=>{const o=aa(n);return Array.from(R).map(E=>{var J;return(J=o.find(te=>te.key===E))==null?void 0:J.label}).filter(Boolean)},[R,n]),s=a.useCallback(o=>{x(E=>{const J=new Set(E);return J.has(o)?J.delete(o):J.add(o),J})},[]),c=a.useCallback(o=>{if(r){const E=new Set(R);E.has(o)?E.delete(o):E.add(o),i==null||i(Array.from(E))}else i==null||i(o),C(!1)},[r,R,i]),l=a.useCallback(o=>{o.stopPropagation(),i==null||i(r?[]:"")},[i,r]);return e.jsxs("div",{className:`nice-field nice-field--${K} ${S||""}`,style:{width:"fit-content",maxWidth:"100%",...v},...j,children:[N&&e.jsx("label",{htmlFor:b,className:`nice-field__label ${H?"nice-field__label--required":""}`,children:N}),e.jsxs("div",{ref:p,className:"nice-tree-select",style:{position:"relative",width:I!=null?typeof I=="number"?`${I}px`:I:240},children:[e.jsxs("div",{ref:A,id:b,className:`nice-input nice-input--${K} ${V?"nice-input--error":""} ${g?"nice-input--disabled":""} ${k?"nice-input--readonly":""}`,role:"combobox","aria-expanded":h,"aria-haspopup":"tree","aria-invalid":!!V,tabIndex:g?-1:0,onClick:()=>!g&&!k&&C(!h),onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),!g&&!k&&C(!h))},children:[e.jsx("span",{className:"nice-tree-select__display",children:u.length>0?u.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:f??Y("controls.select","Select...")})}),M&&R.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:l,"aria-label":Y("controls.clear","Clear"),children:"✕"}),e.jsx("svg",{className:"nice-tree-select__arrow",width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",style:{transform:h?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"})})]}),h&&e.jsxs("div",{className:"nice-tree-select__dropdown",role:"tree",children:[d&&e.jsx("div",{className:"nice-tree-select__search",children:e.jsx("input",{className:"nice-input__native",type:"text",placeholder:Y("controls.search","Search..."),value:w,onChange:o=>O(o.target.value),autoFocus:!0,onClick:o=>o.stopPropagation()})}),e.jsx("div",{className:"nice-tree-select__list",children:y.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:Y("controls.noResults","No results")}):y.map(o=>e.jsx(on,{node:o,level:0,selectedKeys:R,expandedKeys:L,onToggleExpand:s,onSelect:c,selectableLeafsOnly:_},o.key))})]})]}),ee&&e.jsx("input",{type:"hidden",name:ee,value:Array.isArray(t)?t.join(","):t??""}),V&&e.jsx("div",{id:`${b}-error`,className:"nice-field__error",role:"alert",children:V}),!V&&z&&e.jsx("div",{id:`${b}-helper`,className:"nice-field__helper",children:z})]})});cn.displayName="NiceTreeSelect";function Ve(n,t){return String(n[t])}const dn=a.forwardRef(({source:n,target:t,onChange:i,keyField:r="id",labelField:d="label",renderItem:f,filterable:_=!1,sourceHeader:M,targetHeader:N,disabled:z=!1,size:V="md",className:H,style:g,id:k,...K},ee)=>{const{t:X}=F.ue(),[S,v]=a.useState(new Set),[I,j]=a.useState(new Set),[A,Y]=a.useState(""),[b,h]=a.useState(""),C=a.useCallback((y,u,s)=>{u(c=>{const l=new Set(c);return l.has(s)?l.delete(s):l.add(s),l})},[]),w=a.useCallback(()=>{const y=n.filter(s=>S.has(Ve(s,r))),u=n.filter(s=>!S.has(Ve(s,r)));i(u,[...t,...y]),v(new Set)},[n,t,S,r,i]),O=a.useCallback(()=>{const y=t.filter(s=>I.has(Ve(s,r))),u=t.filter(s=>!I.has(Ve(s,r)));i([...n,...y],u),j(new Set)},[n,t,I,r,i]),L=a.useCallback(()=>{i([],[...t,...n]),v(new Set)},[n,t,i]),x=a.useCallback(()=>{i([...n,...t],[]),j(new Set)},[n,t,i]),p=(y,u)=>{if(!u)return y;const s=u.toLowerCase();return y.filter(c=>String(c[d]).toLowerCase().includes(s))},R=(y,u,s,c,l,o)=>{const E=p(y,c);return e.jsxs("div",{className:"nice-picklist__panel",children:[o&&e.jsx("div",{className:"nice-picklist__header",children:o}),_&&e.jsx("div",{className:"nice-picklist__filter",children:e.jsx("input",{className:"nice-input__native",type:"text",placeholder:X("controls.search","Search..."),value:c,onChange:J=>l(J.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true",children:[E.map(J=>{const te=Ve(J,r),q=u.has(te);return e.jsx("div",{className:`nice-picklist__item ${q?"nice-picklist__item--selected":""}`,role:"option","aria-selected":q,onClick:()=>!z&&C(u,s,te),children:f?f(J):String(J[d])},te)}),E.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:X("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:ee,id:k,className:`nice-picklist nice-picklist--${V} ${z?"nice-picklist--disabled":""} ${H||""}`,style:g,...K,children:[R(n,S,v,A,Y,M??X("picklist.source","Available")),e.jsxs("div",{className:"nice-picklist__controls",children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:z||S.size===0,onClick:w,"aria-label":X("picklist.moveRight","Move right"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"})})}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:z||n.length===0,onClick:L,"aria-label":X("picklist.moveAllRight","Move all right"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M4.293 14.707a1 1 0 010-1.414L7.586 10 4.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"}),e.jsx("path",{d:"M10.293 14.707a1 1 0 010-1.414L13.586 10 10.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"})]})}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:z||I.size===0,onClick:O,"aria-label":X("picklist.moveLeft","Move left"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"})})}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:z||t.length===0,onClick:x,"aria-label":X("picklist.moveAllLeft","Move all left"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M15.707 5.293a1 1 0 010 1.414L12.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"}),e.jsx("path",{d:"M9.707 5.293a1 1 0 010 1.414L6.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"})]})})]}),R(t,I,j,b,h,N??X("picklist.target","Selected"))]})});dn.displayName="NicePickList";let Ue=null,Xe=null;const ia="0.45.0",it=`https://cdn.jsdelivr.net/npm/monaco-editor@${ia}/min/vs`,At=15e3;function zt(){var r;const n=window;if((r=n.MonacoEnvironment)!=null&&r.getWorkerUrl)return;const t=`self.MonacoEnvironment={baseUrl:'${it}/'};importScripts('${it}/base/worker/workerMain.js');`,i=URL.createObjectURL(new Blob([t],{type:"text/javascript"}));n.MonacoEnvironment={getWorkerUrl:()=>i}}function Pe(n){var i;if(n!=="auto")return n;if(typeof document>"u")return"vs";const t=document.documentElement.dataset.theme;return t==="dark"?"vs-dark":t==="light"?"vs":(i=window.matchMedia)!=null&&i.call(window,"(prefers-color-scheme: dark)").matches?"vs-dark":"vs"}function un(){return Xe?Promise.resolve(Xe):Ue||(Ue=new Promise((n,t)=>{if(window.monaco){zt(),Xe=window.monaco,n(Xe);return}let i=!1;const r=window.setTimeout(()=>{i||(i=!0,Ue=null,t(new Error(`Monaco editor failed to load within ${At}ms`)))},At),d=document.createElement("script");d.src=`${it}/loader.min.js`,d.async=!0,d.onload=()=>{const f=window.require;f.config({paths:{vs:it}}),zt(),f(["vs/editor/editor.main"],_=>{i||(i=!0,window.clearTimeout(r),Xe=_,n(_))})},d.onerror=()=>{i||(i=!0,window.clearTimeout(r),Ue=null,t(new Error("Failed to load Monaco Editor loader script")))},document.head.appendChild(d)}),Ue)}const kt=a.forwardRef(function(n,t){const{value:i,onChange:r,language:d="plaintext",theme:f="auto",options:_={},height:M=400,width:N="100%",markers:z=[],decorations:V=[],completionProvider:H,onMount:g,onCursorPositionChange:k,onSelectionChange:K,onSave:ee,loading:X,disabled:S=!1,showToolbar:v=!1,showStatusBar:I=!1,editorSize:j="standard",className:A,"data-testid":Y}=n,b=a.useRef(null),h=a.useRef(null),C=a.useRef(null),w=a.useRef([]),O=a.useRef(null),[L,x]=a.useState(!0),[p,R]=a.useState(null),[y,u]=a.useState({lineNumber:1,column:1}),[s,c]=a.useState(""),[l,o]=a.useState(_.wordWrap==="on"),E=a.useMemo(()=>({automaticLayout:!0,readOnly:S||_.readOnly,minimap:{enabled:_.minimap??!0},lineNumbers:_.lineNumbers??"on",wordWrap:_.wordWrap??"off",tabSize:_.tabSize??2,insertSpaces:_.insertSpaces??!0,fontSize:_.fontSize??14,fontFamily:_.fontFamily??"'Fira Code', 'Consolas', 'Monaco', monospace",fontLigatures:_.fontLigatures??!0,cursorStyle:_.cursorStyle??"line",cursorBlinking:_.cursorBlinking??"blink",autoClosingBrackets:_.autoClosingBrackets??"languageDefined",autoClosingQuotes:_.autoClosingQuotes??"languageDefined",formatOnPaste:_.formatOnPaste??!1,formatOnType:_.formatOnType??!1,renderWhitespace:_.renderWhitespace??"selection",renderControlCharacters:_.renderControlCharacters??!1,scrollBeyondLastLine:_.scrollBeyondLastLine??!0,smoothScrolling:_.smoothScrolling??!0,folding:_.folding??!0,showFoldingControls:_.showFoldingControls??"mouseover","bracketPairColorization.enabled":_.bracketPairColorization??!0,guides:_.guides??{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:_.stickyScroll??!1},quickSuggestions:_.quickSuggestions??!0,suggestOnTriggerCharacters:_.suggestOnTriggerCharacters??!0,acceptSuggestionOnEnter:_.acceptSuggestionOnEnter??"on",inlayHints:{enabled:_.inlayHints?"on":"off"}}),[_,S]);a.useEffect(()=>{if(!b.current)return;let $=!0;return un().then(P=>{if(!$||!b.current)return;C.current=P;const W=P.editor.create(b.current,{value:i,language:d,theme:Pe(f),...E});h.current=W,x(!1),W.onDidChangeModelContent(()=>{const le=W.getValue();r==null||r(le)}),W.onDidChangeCursorPosition(le=>{u({lineNumber:le.position.lineNumber,column:le.position.column}),k==null||k({lineNumber:le.position.lineNumber,column:le.position.column})}),W.onDidChangeCursorSelection(le=>{var me;const re=le.selection,pe=((me=W.getModel())==null?void 0:me.getValueInRange(re))??"";c(pe),K==null||K({startLineNumber:re.startLineNumber,startColumn:re.startColumn,endLineNumber:re.endLineNumber,endColumn:re.endColumn})}),W.addCommand(P.KeyMod.CtrlCmd|P.KeyCode.KeyS,()=>{ee==null||ee(W.getValue())}),g==null||g(W,P)}).catch(P=>{$&&(R(P.message??"Failed to load editor"),x(!1))}),()=>{var P,W;$=!1,(P=h.current)==null||P.dispose(),(W=O.current)==null||W.dispose()}},[]),a.useEffect(()=>{const $=h.current;if($&&i!==$.getValue()){const P=$.getPosition();$.setValue(i),P&&$.setPosition(P)}},[i]),a.useEffect(()=>{const $=h.current,P=C.current;if($&&P){const W=$.getModel();W&&P.editor.setModelLanguage(W,d)}},[d]),a.useEffect(()=>{var re,pe;const $=C.current;if(!$||($.editor.setTheme(Pe(f)),f!=="auto"||typeof document>"u"))return;const P=()=>{var me;(me=C.current)==null||me.editor.setTheme(Pe("auto"))},W=new MutationObserver(P);W.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const le=(re=window.matchMedia)==null?void 0:re.call(window,"(prefers-color-scheme: dark)");return(pe=le==null?void 0:le.addEventListener)==null||pe.call(le,"change",P),()=>{var me;W.disconnect(),(me=le==null?void 0:le.removeEventListener)==null||me.call(le,"change",P)}},[f]),a.useEffect(()=>{const $=h.current;$&&$.updateOptions(E)},[E]),a.useEffect(()=>{const $=h.current,P=C.current;if($&&P){const W=$.getModel();if(W){const le=z.map(re=>({startLineNumber:re.startLineNumber,startColumn:re.startColumn,endLineNumber:re.endLineNumber,endColumn:re.endColumn,message:re.message,severity:re.severity}));P.editor.setModelMarkers(W,"owner",le)}}},[z]),a.useEffect(()=>{const $=h.current;if($&&V.length>0){const P=V.map(W=>({range:{startLineNumber:W.range.startLineNumber,startColumn:W.range.startColumn,endLineNumber:W.range.endLineNumber,endColumn:W.range.endColumn},options:{className:W.className,glyphMarginClassName:W.glyphMarginClassName,hoverMessage:W.hoverMessage?{value:W.hoverMessage}:void 0,isWholeLine:W.isWholeLine}}));w.current=$.deltaDecorations(w.current,P)}},[V]),a.useEffect(()=>{var W;const $=C.current;if(!$||!H)return;(W=O.current)==null||W.dispose();const P={text:0,method:1,function:2,constructor:3,field:4,variable:5,class:6,interface:7,module:8,property:9,keyword:13,snippet:14,color:15,file:16,reference:17,folder:18};return O.current=$.languages.registerCompletionItemProvider(d,{provideCompletionItems:async(le,re)=>({suggestions:(await H(le,re)).map(pe=>({label:pe.label,kind:P[pe.kind]??0,insertText:pe.insertText,insertTextRules:pe.insertTextRules==="insertAsSnippet"?4:void 0,documentation:pe.documentation,detail:pe.detail,range:{startLineNumber:re.lineNumber,startColumn:re.column,endLineNumber:re.lineNumber,endColumn:re.column}}))})}),()=>{var le;(le=O.current)==null||le.dispose()}},[d,H]),a.useImperativeHandle(t,()=>({getEditor:()=>h.current,getMonaco:()=>C.current,focus:()=>{var $;return($=h.current)==null?void 0:$.focus()},getValue:()=>{var $;return(($=h.current)==null?void 0:$.getValue())??""},setValue:$=>{var P;return(P=h.current)==null?void 0:P.setValue($)},getSelection:()=>{var W;const $=h.current;if(!$)return"";const P=$.getSelection();return P?((W=$.getModel())==null?void 0:W.getValueInRange(P))??"":""},insertText:$=>{const P=h.current;if(!P)return;const W=P.getSelection();W&&P.executeEdits("",[{range:W,text:$}])},formatDocument:()=>{var $,P;(P=($=h.current)==null?void 0:$.getAction("editor.action.formatDocument"))==null||P.run()},goToLine:($,P=1)=>{const W=h.current;W&&(W.setPosition({lineNumber:$,column:P}),W.revealLineInCenter($),W.focus())},findReplace:()=>{var $,P;(P=($=h.current)==null?void 0:$.getAction("editor.action.startFindReplaceAction"))==null||P.run()},undo:()=>{var $;($=h.current)==null||$.trigger("keyboard","undo",null)},redo:()=>{var $;($=h.current)==null||$.trigger("keyboard","redo",null)},getCursorPosition:()=>{var P;const $=(P=h.current)==null?void 0:P.getPosition();return{lineNumber:($==null?void 0:$.lineNumber)??1,column:($==null?void 0:$.column)??1}},setMarkers:$=>{const P=h.current,W=C.current;if(P&&W){const le=P.getModel();if(le){const re=$.map(pe=>({startLineNumber:pe.startLineNumber,startColumn:pe.startColumn,endLineNumber:pe.endLineNumber,endColumn:pe.endColumn,message:pe.message,severity:pe.severity}));W.editor.setModelMarkers(le,"owner",re)}}}}),[]);const J=a.useMemo(()=>({format:()=>{var $,P;return(P=($=h.current)==null?void 0:$.getAction("editor.action.formatDocument"))==null?void 0:P.run()},undo:()=>{var $;return($=h.current)==null?void 0:$.trigger("keyboard","undo",null)},redo:()=>{var $;return($=h.current)==null?void 0:$.trigger("keyboard","redo",null)},find:()=>{var $,P;return(P=($=h.current)==null?void 0:$.getAction("editor.action.startFindReplaceAction"))==null?void 0:P.run()},toggleWordWrap:()=>{var P;const $=!l;o($),(P=h.current)==null||P.updateOptions({wordWrap:$?"on":"off"})},toggleMinimap:()=>{var P,W,le,re,pe,me;const $=(pe=(P=h.current)==null?void 0:P.getOption)==null?void 0:pe.call(P,(re=(le=(W=C.current)==null?void 0:W.editor)==null?void 0:le.EditorOption)==null?void 0:re.minimap);(me=h.current)==null||me.updateOptions({minimap:{enabled:!($!=null&&$.enabled)}})},foldAll:()=>{var $,P;return(P=($=h.current)==null?void 0:$.getAction("editor.foldAll"))==null?void 0:P.run()},unfoldAll:()=>{var $,P;return(P=($=h.current)==null?void 0:$.getAction("editor.unfoldAll"))==null?void 0:P.run()}}),[l]),te=i.split(`
|
|
12
|
+
`).length,q=i.length;return e.jsxs("div",{className:`nice-code-editor-wrap nice-editor--${j} ${A??""}`,style:{height:M,width:N,display:"flex",flexDirection:"column",position:"relative"},"data-testid":Y,children:[p&&e.jsxs("div",{className:"nice-code-editor__error",style:{position:"absolute",inset:0,zIndex:2,background:"var(--nice-bg-primary, #fff)"},children:[e.jsxs("span",{children:["⚠️ ",p]}),e.jsx("textarea",{value:i,onChange:$=>r==null?void 0:r($.target.value),readOnly:S||_.readOnly,style:{width:"100%",height:"100%",fontFamily:"monospace"}})]}),L&&!p&&e.jsx("div",{className:"nice-code-editor__loader-overlay",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)"},children:X??e.jsx("div",{className:"nice-code-editor__loader",children:"Loading editor..."})}),v&&e.jsxs("div",{className:"nice-code-editor__toolbar",children:[e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.undo,title:"Undo (Ctrl+Z)",children:"↶"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.redo,title:"Redo (Ctrl+Y)",children:"↷"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.format,title:"Format (Shift+Alt+F)",children:"⎘"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.find,title:"Find & Replace (Ctrl+H)",children:"🔍"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:`nice-code-editor__toolbar-btn${l?" nice-code-editor__toolbar-btn--active":""}`,onClick:J.toggleWordWrap,title:"Toggle Word Wrap",children:"↩"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.toggleMinimap,title:"Toggle Minimap",children:"▥"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.foldAll,title:"Fold All",children:"⊟"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.unfoldAll,title:"Unfold All",children:"⊞"})]}),e.jsx("div",{ref:b,className:"nice-code-editor",style:{flex:1,minHeight:0}}),I&&e.jsxs("div",{className:"nice-code-editor__statusbar",children:[e.jsxs("span",{children:["Ln ",y.lineNumber,", Col ",y.column]}),s.length>0&&e.jsxs("span",{children:["(",s.length," selected)"]}),e.jsx("span",{className:"nice-code-editor__statusbar-spacer"}),e.jsxs("span",{children:[te," lines · ",q," chars"]}),e.jsx("span",{className:"nice-code-editor__statusbar-lang",children:d}),z.length>0&&e.jsxs("span",{className:"nice-code-editor__statusbar-markers",children:["⚠ ",z.length]})]})]})});function pn(n){const{original:t,modified:i,language:r="plaintext",theme:d="auto",height:f=400,width:_="100%",inline:M=!1,renderSideBySide:N=!0,originalEditable:z=!1,modifiedEditable:V=!1,onOriginalChange:H,onModifiedChange:g,loading:k,className:K,"data-testid":ee}=n,X=a.useRef(null),S=a.useRef(null),v=a.useRef(null),[I,j]=a.useState(!0),[A,Y]=a.useState(null);return a.useEffect(()=>{if(!X.current)return;let b=!0;return un().then(h=>{if(!b||!X.current)return;v.current=h;const C=h.editor.createModel(t,r),w=h.editor.createModel(i,r),O=h.editor.createDiffEditor(X.current,{automaticLayout:!0,theme:Pe(d),renderSideBySide:!M&&N,originalEditable:z,readOnly:!V});O.setModel({original:C,modified:w}),S.current=O,j(!1),z&&C.onDidChangeContent(()=>{H==null||H(C.getValue())}),V&&w.onDidChangeContent(()=>{g==null||g(w.getValue())})}).catch(h=>{b&&(Y(h.message??"Failed to load diff editor"),j(!1))}),()=>{var h;b=!1,(h=S.current)==null||h.dispose()}},[]),a.useEffect(()=>{const b=S.current;if(!b)return;const h=b.getModel();h&&(h.original.getValue()!==t&&h.original.setValue(t),h.modified.getValue()!==i&&h.modified.setValue(i))},[t,i]),a.useEffect(()=>{var O,L;const b=v.current;if(!b||(b.editor.setTheme(Pe(d)),d!=="auto"||typeof document>"u"))return;const h=()=>{var x;(x=v.current)==null||x.editor.setTheme(Pe("auto"))},C=new MutationObserver(h);C.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const w=(O=window.matchMedia)==null?void 0:O.call(window,"(prefers-color-scheme: dark)");return(L=w==null?void 0:w.addEventListener)==null||L.call(w,"change",h),()=>{var x;C.disconnect(),(x=w==null?void 0:w.removeEventListener)==null||x.call(w,"change",h)}},[d,I]),A?e.jsx("div",{className:`nice-code-diff-editor nice-code-diff-editor--error ${K??""}`,style:{height:f,width:_},"data-testid":ee,children:e.jsx("div",{className:"nice-code-editor__error",children:e.jsxs("span",{children:["⚠️ ",A]})})}):e.jsxs("div",{className:`nice-code-diff-editor ${K??""}`,style:{height:f,width:_,position:"relative"},"data-testid":ee,children:[e.jsx("div",{ref:X,style:{position:"absolute",inset:0}}),I&&e.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)",zIndex:2},children:k??e.jsx("div",{className:"nice-code-editor__loader",children:"Loading diff editor..."})})]})}const ra="1.29.0",It=`https://cdn.jsdelivr.net/npm/prismjs@${ra}`;let ht=null;const xt={javascript:"javascript",typescript:"typescript",json:"json",html:"markup",css:"css",scss:"scss",less:"less",markdown:"markdown",xml:"markup",yaml:"yaml",sql:"sql",python:"python",csharp:"csharp",java:"java",cpp:"cpp",c:"c",go:"go",rust:"rust",php:"php",ruby:"ruby",shell:"bash",powershell:"powershell",plaintext:"plain"};function Lt(n){return new Promise((t,i)=>{if(document.querySelector(`script[data-prism-src="${n}"]`)){t();return}const r=document.createElement("script");r.src=n,r.async=!0,r.dataset.prismSrc=n,r.onload=()=>t(),r.onerror=()=>i(new Error(`Failed to load ${n}`)),document.head.appendChild(r)})}function la(n){if(typeof window>"u")return Promise.resolve(null);const t=window,i=xt[n]??"plain",r=async()=>{var d,f;if(i!=="plain"&&!((f=(d=t.Prism)==null?void 0:d.languages)!=null&&f[i]))try{await Lt(`${It}/components/prism-${i}.min.js`)}catch{}};return t.Prism?r().then(()=>t.Prism):(ht||(ht=(async()=>(window.Prism={manual:!0},await Lt(`${It}/prism.min.js`),window.Prism))()),ht.then(async()=>(await r(),window.Prism)))}function mt(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function hn(n){const{value:t,onChange:i,language:r="plaintext",height:d=300,width:f="100%",readOnly:_=!1,tabSize:M=2,lineNumbers:N=!0,placeholder:z,theme:V="auto",className:H,"data-testid":g}=n,k=a.useRef(null),K=a.useRef(null),[ee,X]=a.useState(()=>mt(t)),[S,v]=a.useState("light");a.useEffect(()=>{var O,L;const b=()=>{var p;if(V!=="auto")return V;if(typeof document>"u")return"light";const x=document.documentElement.dataset.theme;return x==="dark"?"dark":x==="light"?"light":(p=window.matchMedia)!=null&&p.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"};if(v(b()),V!=="auto"||typeof document>"u")return;const h=()=>v(b()),C=new MutationObserver(h);C.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const w=(O=window.matchMedia)==null?void 0:O.call(window,"(prefers-color-scheme: dark)");return(L=w==null?void 0:w.addEventListener)==null||L.call(w,"change",h),()=>{var x;C.disconnect(),(x=w==null?void 0:w.removeEventListener)==null||x.call(w,"change",h)}},[V]),a.useEffect(()=>{let b=!0;return la(r).then(h=>{var w;if(!b)return;const C=xt[r]??"plain";if((w=h==null?void 0:h.languages)!=null&&w[C])try{const O=h.highlight(t,h.languages[C],C);X(O);return}catch{}X(mt(t))}).catch(()=>{b&&X(mt(t))}),()=>{b=!1}},[t,r]);const I=a.useCallback(()=>{!K.current||!k.current||(K.current.scrollTop=k.current.scrollTop,K.current.scrollLeft=k.current.scrollLeft)},[]),j=a.useCallback(b=>{var h;if(b.key==="Tab"){b.preventDefault();const C=b.currentTarget,w=C.selectionStart,O=C.selectionEnd,L=" ".repeat(M);if(b.shiftKey){const x=t.substring(0,w).lastIndexOf(`
|
|
13
|
+
`)+1;if((((h=t.substring(x,w).match(/^(\s*)/))==null?void 0:h[1])??"").length>=M){const p=t.substring(0,x)+t.substring(x+M);i==null||i(p),setTimeout(()=>{C.selectionStart=C.selectionEnd=w-M},0)}}else{const x=t.substring(0,w)+L+t.substring(O);i==null||i(x),setTimeout(()=>{C.selectionStart=C.selectionEnd=w+M},0)}}},[t,i,M]),A=t.split(`
|
|
14
|
+
`).length,Y=xt[r]??"plain";return e.jsxs("div",{className:`nice-simple-code-editor nice-simple-code-editor--${S} ${H??""}`,style:{height:d,width:f},"data-testid":g,"data-language":r,"data-theme":S,children:[N&&e.jsx("div",{className:"nice-simple-code-editor__line-numbers",children:Array.from({length:A},(b,h)=>e.jsx("div",{className:"nice-simple-code-editor__line-number",children:h+1},h))}),e.jsxs("div",{className:"nice-simple-code-editor__editor-area",children:[e.jsx("pre",{ref:K,"aria-hidden":"true",className:`nice-simple-code-editor__highlight language-${Y}`,children:e.jsx("code",{className:`language-${Y}`,dangerouslySetInnerHTML:{__html:ee+(t.endsWith(`
|
|
15
|
+
`)?`
|
|
16
|
+
`:"")}})}),e.jsx("textarea",{ref:k,className:"nice-simple-code-editor__textarea",value:t,onChange:b=>i==null?void 0:i(b.target.value),onKeyDown:j,onScroll:I,readOnly:_,placeholder:z,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off"})]})]})}const Ot="nice-code-editor-styles";if(typeof document<"u"&&!document.getElementById(Ot)){const n=document.createElement("style");n.id=Ot,n.textContent=`
|
|
17
|
+
.nice-code-editor,
|
|
18
|
+
.nice-code-diff-editor {
|
|
19
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.nice-code-editor--loading,
|
|
25
|
+
.nice-code-editor--error,
|
|
26
|
+
.nice-code-diff-editor--loading {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
background: var(--nice-bg-muted, #f5f5f5);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.nice-code-editor__loader {
|
|
34
|
+
color: var(--nice-text-secondary, #666);
|
|
35
|
+
font-size: 14px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.nice-code-editor__error {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: 100%;
|
|
43
|
+
padding: 8px;
|
|
44
|
+
gap: 8px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.nice-code-editor__error span {
|
|
48
|
+
color: var(--nice-error, #d32f2f);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Simple code editor */
|
|
52
|
+
.nice-simple-code-editor {
|
|
53
|
+
display: flex;
|
|
54
|
+
border: 1px solid var(--border-color, var(--nice-border, #e0e0e0));
|
|
55
|
+
border-radius: 4px;
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
58
|
+
font-size: 14px;
|
|
59
|
+
line-height: 1.5;
|
|
60
|
+
background: var(--bg-primary, var(--nice-bg-surface, #fff));
|
|
61
|
+
color: var(--text-primary, var(--nice-text-primary, #333));
|
|
62
|
+
}
|
|
63
|
+
.nice-simple-code-editor--dark {
|
|
64
|
+
background: #1e1e1e;
|
|
65
|
+
color: #d4d4d4;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.nice-simple-code-editor__line-numbers {
|
|
69
|
+
padding: 8px 0;
|
|
70
|
+
background: var(--bg-secondary, var(--nice-bg-muted, #f5f5f5));
|
|
71
|
+
border-right: 1px solid var(--border-color, var(--nice-border, #e0e0e0));
|
|
72
|
+
user-select: none;
|
|
73
|
+
text-align: right;
|
|
74
|
+
color: var(--text-secondary, var(--nice-text-secondary, #999));
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
}
|
|
77
|
+
.nice-simple-code-editor--dark .nice-simple-code-editor__line-numbers {
|
|
78
|
+
background: #252526;
|
|
79
|
+
border-right-color: #3c3c3c;
|
|
80
|
+
color: #858585;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.nice-simple-code-editor__line-number {
|
|
84
|
+
padding: 0 12px;
|
|
85
|
+
min-width: 40px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.nice-simple-code-editor__editor-area {
|
|
89
|
+
position: relative;
|
|
90
|
+
flex: 1;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.nice-simple-code-editor__highlight,
|
|
95
|
+
.nice-simple-code-editor__textarea {
|
|
96
|
+
position: absolute;
|
|
97
|
+
inset: 0;
|
|
98
|
+
margin: 0;
|
|
99
|
+
padding: 8px 12px;
|
|
100
|
+
border: 0;
|
|
101
|
+
font: inherit;
|
|
102
|
+
line-height: inherit;
|
|
103
|
+
white-space: pre;
|
|
104
|
+
overflow: auto;
|
|
105
|
+
tab-size: 2;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.nice-simple-code-editor__highlight {
|
|
109
|
+
pointer-events: none;
|
|
110
|
+
background: transparent;
|
|
111
|
+
color: inherit;
|
|
112
|
+
}
|
|
113
|
+
.nice-simple-code-editor__highlight code {
|
|
114
|
+
font: inherit;
|
|
115
|
+
background: transparent;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.nice-simple-code-editor__textarea {
|
|
119
|
+
background: transparent;
|
|
120
|
+
color: transparent;
|
|
121
|
+
caret-color: var(--text-primary, var(--nice-text-primary, #333));
|
|
122
|
+
resize: none;
|
|
123
|
+
outline: none;
|
|
124
|
+
-webkit-text-fill-color: transparent;
|
|
125
|
+
}
|
|
126
|
+
.nice-simple-code-editor--dark .nice-simple-code-editor__textarea {
|
|
127
|
+
caret-color: #d4d4d4;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.nice-simple-code-editor__textarea::placeholder {
|
|
131
|
+
color: var(--text-secondary, var(--nice-text-secondary, #999));
|
|
132
|
+
-webkit-text-fill-color: var(--text-secondary, var(--nice-text-secondary, #999));
|
|
133
|
+
}
|
|
134
|
+
.nice-simple-code-editor--dark .nice-simple-code-editor__textarea::placeholder {
|
|
135
|
+
color: #858585;
|
|
136
|
+
-webkit-text-fill-color: #858585;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Prism token colors — light */
|
|
140
|
+
.nice-simple-code-editor .token.comment,
|
|
141
|
+
.nice-simple-code-editor .token.prolog,
|
|
142
|
+
.nice-simple-code-editor .token.doctype,
|
|
143
|
+
.nice-simple-code-editor .token.cdata { color: #6a737d; font-style: italic; }
|
|
144
|
+
.nice-simple-code-editor .token.punctuation { color: #586069; }
|
|
145
|
+
.nice-simple-code-editor .token.property,
|
|
146
|
+
.nice-simple-code-editor .token.tag,
|
|
147
|
+
.nice-simple-code-editor .token.boolean,
|
|
148
|
+
.nice-simple-code-editor .token.number,
|
|
149
|
+
.nice-simple-code-editor .token.constant,
|
|
150
|
+
.nice-simple-code-editor .token.symbol,
|
|
151
|
+
.nice-simple-code-editor .token.deleted { color: #005cc5; }
|
|
152
|
+
.nice-simple-code-editor .token.selector,
|
|
153
|
+
.nice-simple-code-editor .token.attr-name,
|
|
154
|
+
.nice-simple-code-editor .token.string,
|
|
155
|
+
.nice-simple-code-editor .token.char,
|
|
156
|
+
.nice-simple-code-editor .token.builtin,
|
|
157
|
+
.nice-simple-code-editor .token.inserted { color: #032f62; }
|
|
158
|
+
.nice-simple-code-editor .token.operator,
|
|
159
|
+
.nice-simple-code-editor .token.entity,
|
|
160
|
+
.nice-simple-code-editor .token.url,
|
|
161
|
+
.nice-simple-code-editor .token.variable { color: #d73a49; }
|
|
162
|
+
.nice-simple-code-editor .token.atrule,
|
|
163
|
+
.nice-simple-code-editor .token.attr-value,
|
|
164
|
+
.nice-simple-code-editor .token.keyword { color: #d73a49; font-weight: 600; }
|
|
165
|
+
.nice-simple-code-editor .token.function,
|
|
166
|
+
.nice-simple-code-editor .token.class-name { color: #6f42c1; }
|
|
167
|
+
.nice-simple-code-editor .token.regex,
|
|
168
|
+
.nice-simple-code-editor .token.important { color: #e36209; }
|
|
169
|
+
|
|
170
|
+
/* Prism token colors — dark */
|
|
171
|
+
.nice-simple-code-editor--dark .token.comment,
|
|
172
|
+
.nice-simple-code-editor--dark .token.prolog,
|
|
173
|
+
.nice-simple-code-editor--dark .token.doctype,
|
|
174
|
+
.nice-simple-code-editor--dark .token.cdata { color: #6a9955; font-style: italic; }
|
|
175
|
+
.nice-simple-code-editor--dark .token.punctuation { color: #d4d4d4; }
|
|
176
|
+
.nice-simple-code-editor--dark .token.property,
|
|
177
|
+
.nice-simple-code-editor--dark .token.tag,
|
|
178
|
+
.nice-simple-code-editor--dark .token.boolean,
|
|
179
|
+
.nice-simple-code-editor--dark .token.number,
|
|
180
|
+
.nice-simple-code-editor--dark .token.constant,
|
|
181
|
+
.nice-simple-code-editor--dark .token.symbol,
|
|
182
|
+
.nice-simple-code-editor--dark .token.deleted { color: #b5cea8; }
|
|
183
|
+
.nice-simple-code-editor--dark .token.selector,
|
|
184
|
+
.nice-simple-code-editor--dark .token.attr-name,
|
|
185
|
+
.nice-simple-code-editor--dark .token.string,
|
|
186
|
+
.nice-simple-code-editor--dark .token.char,
|
|
187
|
+
.nice-simple-code-editor--dark .token.builtin,
|
|
188
|
+
.nice-simple-code-editor--dark .token.inserted { color: #ce9178; }
|
|
189
|
+
.nice-simple-code-editor--dark .token.operator,
|
|
190
|
+
.nice-simple-code-editor--dark .token.entity,
|
|
191
|
+
.nice-simple-code-editor--dark .token.url,
|
|
192
|
+
.nice-simple-code-editor--dark .token.variable { color: #569cd6; }
|
|
193
|
+
.nice-simple-code-editor--dark .token.atrule,
|
|
194
|
+
.nice-simple-code-editor--dark .token.attr-value,
|
|
195
|
+
.nice-simple-code-editor--dark .token.keyword { color: #c586c0; font-weight: 600; }
|
|
196
|
+
.nice-simple-code-editor--dark .token.function,
|
|
197
|
+
.nice-simple-code-editor--dark .token.class-name { color: #dcdcaa; }
|
|
198
|
+
.nice-simple-code-editor--dark .token.regex,
|
|
199
|
+
.nice-simple-code-editor--dark .token.important { color: #d7ba7d; }
|
|
200
|
+
|
|
201
|
+
/* Toolbar */
|
|
202
|
+
.nice-code-editor-wrap {
|
|
203
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
204
|
+
border-radius: 4px;
|
|
205
|
+
overflow: hidden;
|
|
206
|
+
}
|
|
207
|
+
.nice-code-editor-wrap .nice-code-editor {
|
|
208
|
+
border: none;
|
|
209
|
+
border-radius: 0;
|
|
210
|
+
}
|
|
211
|
+
.nice-code-editor__toolbar {
|
|
212
|
+
display: flex;
|
|
213
|
+
align-items: center;
|
|
214
|
+
gap: 2px;
|
|
215
|
+
padding: 3px 6px;
|
|
216
|
+
background: var(--nice-bg-muted, #f5f5f5);
|
|
217
|
+
border-bottom: 1px solid var(--nice-border, #e0e0e0);
|
|
218
|
+
}
|
|
219
|
+
.nice-code-editor__toolbar-btn {
|
|
220
|
+
display: inline-flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
justify-content: center;
|
|
223
|
+
width: 26px;
|
|
224
|
+
height: 26px;
|
|
225
|
+
border: none;
|
|
226
|
+
border-radius: 3px;
|
|
227
|
+
background: transparent;
|
|
228
|
+
color: var(--nice-text-secondary, #666);
|
|
229
|
+
cursor: pointer;
|
|
230
|
+
font-size: 14px;
|
|
231
|
+
transition: background 0.15s, color 0.15s;
|
|
232
|
+
}
|
|
233
|
+
.nice-code-editor__toolbar-btn:hover {
|
|
234
|
+
background: var(--nice-hover, #e0e0e0);
|
|
235
|
+
color: var(--nice-text-primary, #333);
|
|
236
|
+
}
|
|
237
|
+
.nice-code-editor__toolbar-btn--active {
|
|
238
|
+
background: var(--nice-accent, #1976d2);
|
|
239
|
+
color: #fff;
|
|
240
|
+
}
|
|
241
|
+
.nice-code-editor__toolbar-sep {
|
|
242
|
+
width: 1px;
|
|
243
|
+
height: 18px;
|
|
244
|
+
background: var(--nice-border, #e0e0e0);
|
|
245
|
+
margin: 0 4px;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Status bar */
|
|
249
|
+
.nice-code-editor__statusbar {
|
|
250
|
+
display: flex;
|
|
251
|
+
align-items: center;
|
|
252
|
+
gap: 12px;
|
|
253
|
+
padding: 2px 10px;
|
|
254
|
+
background: var(--nice-bg-muted, #f5f5f5);
|
|
255
|
+
border-top: 1px solid var(--nice-border, #e0e0e0);
|
|
256
|
+
font-size: 12px;
|
|
257
|
+
color: var(--nice-text-secondary, #666);
|
|
258
|
+
user-select: none;
|
|
259
|
+
}
|
|
260
|
+
.nice-code-editor__statusbar-spacer { flex: 1; }
|
|
261
|
+
.nice-code-editor__statusbar-lang {
|
|
262
|
+
text-transform: uppercase;
|
|
263
|
+
font-weight: 600;
|
|
264
|
+
font-size: 11px;
|
|
265
|
+
}
|
|
266
|
+
.nice-code-editor__statusbar-markers {
|
|
267
|
+
color: var(--nice-warning, #f39c12);
|
|
268
|
+
font-weight: 600;
|
|
269
|
+
}
|
|
270
|
+
`,document.head.appendChild(n)}const sa=Object.freeze(Object.defineProperty({__proto__:null,NiceCodeDiffEditor:pn,NiceCodeEditor:kt,NiceSimpleCodeEditor:hn},Symbol.toStringTag,{value:"Module"}));a.forwardRef(function(n,t){const{enableAI:i=!0,aiModel:r,enableInlineCompletion:d=!0,completionDelay:f=500,enableExplain:_=!0,enableRefactor:M=!0,enableGenerate:N=!0,systemPrompt:z,onExplain:V,onRefactor:H,showAIToolbar:g=!0,aiShortcutKey:k="Ctrl",language:K="plaintext",value:ee,onChange:X,...S}=n,v=a.useRef(null),[I,j]=a.useState(null),[A,Y]=a.useState(!1),[b,h]=a.useState(""),[C,w]=a.useState(!1),[O,L]=a.useState(""),[x,p]=a.useState(""),[R,y]=a.useState(""),u=a.useRef(),{t:s}=F.ue(),c=F.me(),{complete:l,explain:o,refactor:E,generateFromComment:J,isLoading:te}=F.vd({language:K,model:r}),q=i&&c.isConfigured,$=a.useCallback(async()=>{if(!q||!d||!v.current||!v.current.getEditor())return;const ne=v.current.getCursorPosition(),de=v.current.getValue().split(`
|
|
271
|
+
`),ue=de.slice(0,ne.lineNumber-1),ve=de[ne.lineNumber-1]||"",se=[...ue,ve.slice(0,ne.column-1)].join(`
|
|
272
|
+
`),D=[ve.slice(ne.column-1),...de.slice(ne.lineNumber)].join(`
|
|
273
|
+
`);try{const T=await l(se,D);T&&j({lineNumber:ne.lineNumber,column:ne.column,text:T})}catch{}},[q,d,l]),P=a.useCallback(async()=>{if(!q||!_||!v.current)return"";const ne=v.current.getSelection();if(!ne)return"";y(ne),Y(!0),h("");try{const de=await o(ne);return h(de),V==null||V(ne,de),de}catch{return h(s("codeEditorAI.explanationFailed","Failed to explain code")),""}},[q,_,o,V,s]),W=a.useCallback(async ne=>{if(!q||!M||!v.current)return"";const de=v.current.getSelection();if(!de)return"";try{const ue=await E(de,ne);return p(ue),H==null||H(de,ue),ue}catch{return""}},[q,M,E,H]),le=a.useCallback(async()=>{var ve;if(!q||!N||!v.current)return;const ne=v.current.getCursorPosition(),de=v.current.getValue().split(`
|
|
274
|
+
`);let ue="";for(let se=ne.lineNumber-1;se>=0&&se>=ne.lineNumber-3;se--){const D=((ve=de[se])==null?void 0:ve.trim())||"";if(D.startsWith("//")||D.startsWith("#")||D.startsWith("/*")||D.startsWith("*")){ue=D.replace(/^\/\/\s*|^#\s*|^\/\*\s*|\*\/\s*$|^\*\s*/g,"").trim();break}}if(ue)try{const se=await J(ue);se&&v.current&&v.current.insertText(`
|
|
275
|
+
`+se)}catch{}},[q,N,J]),re=a.useCallback(()=>{!I||!v.current||(v.current.insertText(I.text),j(null))},[I]),pe=a.useCallback(()=>{j(null)},[]),me=a.useCallback(ne=>{var de;(de=n.onCursorPositionChange)==null||de.call(n,ne),!(!q||!d)&&(u.current&&clearTimeout(u.current),j(null),u.current=setTimeout(()=>{$()},f))},[n.onCursorPositionChange,q,d,f,$]);a.useEffect(()=>{var de;if(!((de=v.current)!=null&&de.getEditor())||!q)return;const ne=ue=>{var ve;if(k==="Ctrl"&&ue.ctrlKey||k==="Alt"&&ue.altKey||k==="Meta"&&ue.metaKey){if(ue.key===" "&&d&&(ue.preventDefault(),$()),ue.key==="e"&&_&&(ue.preventDefault(),P()),ue.key==="r"&&M){ue.preventDefault();const se=(ve=v.current)==null?void 0:ve.getSelection();se&&(y(se),w(!0))}ue.key==="g"&&N&&(ue.preventDefault(),le())}ue.key==="Tab"&&I&&(ue.preventDefault(),re()),ue.key==="Escape"&&I&&pe()};return window.addEventListener("keydown",ne),()=>window.removeEventListener("keydown",ne)},[q,k,d,_,M,N,$,P,le,I,re,pe]),a.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]);const Ne=a.useCallback(()=>{if(!x||!v.current)return;const ne=v.current.getEditor();if(ne!=null&&ne.executeEdits&&(ne!=null&&ne.getSelection)){const de=ne.getSelection();ne.executeEdits("ai-refactor",[{range:de,text:x}])}w(!1),p(""),L("")},[x]);return a.useImperativeHandle(t,()=>({...v.current,getEditor:()=>{var ne;return(ne=v.current)==null?void 0:ne.getEditor()},getMonaco:()=>{var ne;return(ne=v.current)==null?void 0:ne.getMonaco()},focus:()=>{var ne;return(ne=v.current)==null?void 0:ne.focus()},getValue:()=>{var ne;return((ne=v.current)==null?void 0:ne.getValue())||""},setValue:ne=>{var de;return(de=v.current)==null?void 0:de.setValue(ne)},getSelection:()=>{var ne;return((ne=v.current)==null?void 0:ne.getSelection())||""},insertText:ne=>{var de;return(de=v.current)==null?void 0:de.insertText(ne)},formatDocument:()=>{var ne;return(ne=v.current)==null?void 0:ne.formatDocument()},goToLine:(ne,de)=>{var ue;return(ue=v.current)==null?void 0:ue.goToLine(ne,de)},findReplace:()=>{var ne;return(ne=v.current)==null?void 0:ne.findReplace()},undo:()=>{var ne;return(ne=v.current)==null?void 0:ne.undo()},redo:()=>{var ne;return(ne=v.current)==null?void 0:ne.redo()},getCursorPosition:()=>{var ne;return((ne=v.current)==null?void 0:ne.getCursorPosition())||{lineNumber:1,column:1}},setMarkers:ne=>{var de;return(de=v.current)==null?void 0:de.setMarkers(ne)},triggerCompletion:$,explainSelection:P,refactorSelection:W,generateFromComment:le,acceptCompletion:re,dismissCompletion:pe})),e.jsxs("div",{className:"nice-code-editor-ai","data-testid":n["data-testid"],children:[g&&q&&e.jsxs("div",{className:"nice-code-editor-ai__toolbar",children:[e.jsxs("div",{className:"nice-code-editor-ai__toolbar-left",children:[e.jsx("span",{className:"nice-code-editor-ai__toolbar-badge",children:"AI"}),te&&e.jsx("span",{className:"nice-code-editor-ai__loading",children:s("codeEditorAI.loading","Thinking...")})]}),e.jsxs("div",{className:"nice-code-editor-ai__toolbar-right",children:[d&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>$(),disabled:te,title:`${s("codeEditorAI.complete","Complete")} (${k}+Space)`,children:["💡 ",s("codeEditorAI.complete","Complete")]}),_&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>P(),disabled:te,title:`${s("codeEditorAI.explain","Explain")} (${k}+E)`,children:["📖 ",s("codeEditorAI.explain","Explain")]}),M&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>{var de;const ne=(de=v.current)==null?void 0:de.getSelection();ne&&(y(ne),w(!0))},disabled:te,title:`${s("codeEditorAI.refactor","Refactor")} (${k}+R)`,children:["🔧 ",s("codeEditorAI.refactor","Refactor")]}),N&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>le(),disabled:te,title:`${s("codeEditorAI.generate","Generate")} (${k}+G)`,children:["⚡ ",s("codeEditorAI.generate","Generate")]})]})]}),e.jsxs("div",{className:"nice-code-editor-ai__editor-wrapper",children:[e.jsx(kt,{ref:v,value:ee,onChange:X,language:K,onCursorPositionChange:me,...S}),I&&e.jsxs("div",{className:"nice-code-editor-ai__ghost-text",style:{top:`calc(${(I.lineNumber-1)*19}px + 4px)`,left:`calc(${(I.column-1)*7.8}px + 60px)`},children:[e.jsx("span",{className:"nice-code-editor-ai__ghost-text-content",children:I.text}),e.jsxs("span",{className:"nice-code-editor-ai__ghost-text-hint",children:["Tab ",s("codeEditorAI.toAccept","to accept")]})]})]}),A&&e.jsxs("div",{className:"nice-code-editor-ai__panel nice-code-editor-ai__panel--explain",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("h4",{children:["📖 ",s("codeEditorAI.explanation","Explanation")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>Y(!1),children:"✕"})]}),e.jsx("div",{className:"nice-code-editor-ai__panel-body",children:te?e.jsx("div",{className:"nice-code-editor-ai__panel-loading",children:s("codeEditorAI.analyzing","Analyzing code...")}):e.jsxs("div",{className:"nice-code-editor-ai__explanation",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:R}),e.jsx("div",{className:"nice-code-editor-ai__explanation-text",children:b||s("codeEditorAI.noExplanation","Select code and click Explain")})]})})]}),C&&e.jsxs("div",{className:"nice-code-editor-ai__panel nice-code-editor-ai__panel--refactor",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("h4",{children:["🔧 ",s("codeEditorAI.refactorCode","Refactor Code")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>{w(!1),p(""),L("")},children:"✕"})]}),e.jsxs("div",{className:"nice-code-editor-ai__panel-body",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:R}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-input",children:[e.jsx("input",{type:"text",placeholder:s("codeEditorAI.refactorInstruction",'Describe how to refactor (e.g., "extract function", "add error handling")'),value:O,onChange:ne=>L(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&O&&W(O)}}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__refactor-btn",onClick:()=>W(O),disabled:te||!O,children:te?s("codeEditorAI.refactoring","Refactoring..."):s("codeEditorAI.refactor","Refactor")})]}),x&&e.jsxs("div",{className:"nice-code-editor-ai__refactor-result",children:[e.jsx("h5",{children:s("codeEditorAI.refactoredCode","Refactored Code")}),e.jsx("pre",{className:"nice-code-editor-ai__code-preview nice-code-editor-ai__code-preview--result",children:x}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-actions",children:[e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-apply",onClick:Ne,children:["✓ ",s("codeEditorAI.apply","Apply")]}),e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-discard",onClick:()=>{p(""),L("")},children:["✕ ",s("codeEditorAI.discard","Discard")]})]})]})]})]})]})});function Ft(n,t){const i=t.getBoundingClientRect();let r,d,f;if("touches"in n){const _=n.touches[0];r=_.clientX-i.left,d=_.clientY-i.top,f=_.force}else"pressure"in n?(r=n.clientX-i.left,d=n.clientY-i.top,f=n.pressure):(r=n.clientX-i.left,d=n.clientY-i.top);return{x:r,y:d,time:Date.now(),pressure:f!==void 0?f:.5}}function Pt(n,t,i,r,d){if(!t)return(i+r)/2;const f=Math.sqrt(Math.pow(n.x-t.x,2)+Math.pow(n.y-t.y,2))/Math.max(1,n.time-t.time),_=Math.min(f/5,1),M=r-_*(r-i),N=n.pressure??.5,z=i+N*(r-i);return M*.7+z*.3}function Ht(n,t,i,r){n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(i.x,i.y),n.lineWidth=r,n.lineCap="round",n.lineJoin="round",n.stroke()}a.forwardRef(function(n,t){const{value:i,onChange:r,width:d="100%",height:f=200,penColor:_="var(--text-primary, #000000)",penWidth:M=2,minWidth:N=.5,maxWidth:z=4,backgroundColor:V="var(--bg-primary, #ffffff)",placeholder:H="Sign here",showClearButton:g=!0,showUndoButton:k=!0,showColorPicker:K=!1,showSizeSlider:ee=!1,velocityFilterWeight:X=.7,throttle:S=16,disabled:v=!1,readOnly:I=!1,displayMode:j=!1,onBegin:A,onEnd:Y,className:b,"data-testid":h}=n,C=I||j,w=j?!1:g,O=j?!1:k,L=j?!1:K,x=j?!1:ee,p=a.useRef(null),[R,y]=a.useState((i==null?void 0:i.strokes)??[]),[u,s]=a.useState([]),[c,l]=a.useState(!1),[o,E]=a.useState(_),[J,te]=a.useState(M),q=a.useRef(null),$=a.useRef(0),P=R.length===0&&u.length===0;a.useEffect(()=>{const se=p.current;if(!se)return;const D=se.getContext("2d");if(!D)return;const T=se.getBoundingClientRect(),ae=window.devicePixelRatio||1;se.width=T.width*ae,se.height=T.height*ae,D.scale(ae,ae),W()},[d,f]);const W=a.useCallback(()=>{const se=p.current;if(!se)return;const D=se.getContext("2d");if(!D)return;const T=se.getBoundingClientRect();D.fillStyle=V,D.fillRect(0,0,T.width,T.height),R.forEach(ae=>{if(D.strokeStyle=ae.color,!(ae.points.length<2))for(let Q=1;Q<ae.points.length;Q++){const B=ae.points[Q-1],ie=ae.points[Q],oe=Pt(ie,B,N,z);Ht(D,B,ie,oe)}})},[R,V,N,z,X]);a.useEffect(()=>{W()},[W]),a.useEffect(()=>{i!=null&&i.strokes&&y(i.strokes)},[i]),a.useEffect(()=>{const se=p.current;if(se)if(R.length===0)r==null||r(null);else{const D=se.getBoundingClientRect();r==null||r({strokes:R,width:D.width,height:D.height,timestamp:Date.now()})}},[R,r]);const le=a.useCallback(se=>{if(v||C)return;const D=p.current;if(!D)return;D.setPointerCapture(se.pointerId);const T=Ft(se.nativeEvent,D);l(!0),s([T]),q.current=T,$.current=T.time,A==null||A()},[v,C,A]),re=a.useCallback(se=>{if(!c||v||C)return;const D=p.current;if(!D)return;const T=D.getContext("2d");if(!T)return;const ae=Date.now();if(ae-$.current<S)return;const Q=Ft(se.nativeEvent,D),B=q.current;if(B){T.strokeStyle=o;const ie=Pt(Q,B,N,z);Ht(T,B,Q,ie)}s(ie=>[...ie,Q]),q.current=Q,$.current=ae},[c,v,C,o,N,z,X,S]),pe=a.useCallback(se=>{if(!c)return;const D=p.current;if(D&&D.releasePointerCapture(se.pointerId),u.length>0){const T={points:u,color:o,width:J};y(ae=>[...ae,T])}l(!1),s([]),q.current=null,Y==null||Y()},[c,u,o,J,Y]),me=a.useCallback(()=>{y([]),s([]),W()},[W]),Ne=a.useCallback(()=>{y(se=>se.slice(0,-1))},[]),ne=a.useCallback((se="png",D=.92)=>{const T=p.current;if(!T)return"";const ae=se==="jpeg"?"image/jpeg":"image/png";return T.toDataURL(ae,D)},[]),de=a.useCallback(async(se="png",D=.92)=>{const T=p.current;return T?new Promise(ae=>{const Q=se==="jpeg"?"image/jpeg":"image/png";T.toBlob(B=>ae(B),Q,D)}):null},[]),ue=a.useCallback(()=>{const se=p.current;if(!se)return"";const D=se.getBoundingClientRect(),T=R.map(ae=>ae.points.length<2?"":`<path d="${ae.points.reduce((Q,B,ie)=>ie===0?`M ${B.x} ${B.y}`:`${Q} L ${B.x} ${B.y}`,"")}" stroke="${ae.color}" stroke-width="${ae.width}" fill="none" stroke-linecap="round" stroke-linejoin="round"/>`).join(`
|
|
276
|
+
`);return`<svg xmlns="http://www.w3.org/2000/svg" width="${D.width}" height="${D.height}" viewBox="0 0 ${se.width} ${se.height}">
|
|
277
|
+
<rect width="100%" height="100%" fill="${V}"/>
|
|
278
|
+
${T}
|
|
279
|
+
</svg>`},[R,V]);a.useImperativeHandle(t,()=>({clear:me,undo:Ne,isEmpty:()=>R.length===0,getData:()=>{const se=p.current;if(!se||R.length===0)return null;const D=se.getBoundingClientRect();return{strokes:R,width:D.width,height:D.height,timestamp:Date.now()}},setData:se=>{y(se.strokes)},toDataURL:ne,toBlob:de,toSVG:ue,getCanvas:()=>p.current}),[R,me,Ne,ne,de,ue]),a.useEffect(()=>{const se=p.current;if(!se)return;const D=T=>{c&&T.preventDefault()};return se.addEventListener("touchmove",D,{passive:!1}),()=>se.removeEventListener("touchmove",D)},[c]);const ve=w||O||L||x;return e.jsxs("div",{className:`nice-signature ${v?"nice-signature--disabled":""} ${C?"nice-signature--readonly":""} ${b??""}`,style:{width:d},"data-testid":h,children:[ve&&e.jsxs("div",{className:"nice-signature__toolbar",children:[L&&e.jsx("div",{className:"nice-signature__color-picker",children:e.jsx("input",{type:"color",value:o,onChange:se=>E(se.target.value),disabled:v||C,title:"Pen color"})}),x&&e.jsx("div",{className:"nice-signature__size-slider",children:e.jsx("input",{type:"range",min:N,max:z,step:.5,value:J,onChange:se=>te(parseFloat(se.target.value)),disabled:v||C,title:"Pen size"})}),e.jsxs("div",{className:"nice-signature__actions",children:[O&&e.jsx("button",{type:"button",onClick:Ne,disabled:v||C||R.length===0,className:"nice-signature__btn",title:"Undo",children:"↩️"}),w&&e.jsx("button",{type:"button",onClick:me,disabled:v||C||P,className:"nice-signature__btn",title:"Clear",children:"🗑️"})]})]}),e.jsxs("div",{className:"nice-signature__canvas-wrapper",style:{height:f},children:[e.jsx("canvas",{ref:p,className:"nice-signature__canvas",style:{width:"100%",height:"100%",cursor:v||C?"not-allowed":"crosshair",touchAction:"none"},onPointerDown:le,onPointerMove:re,onPointerUp:pe,onPointerLeave:pe}),P&&!c&&H&&e.jsx("div",{className:"nice-signature__placeholder",children:H}),e.jsx("div",{className:"nice-signature__line"})]})]})});const Kt="nice-signature-styles";if(typeof document<"u"&&!document.getElementById(Kt)){const n=document.createElement("style");n.id=Kt,n.textContent=`
|
|
280
|
+
.nice-signature {
|
|
281
|
+
display: flex;
|
|
282
|
+
flex-direction: column;
|
|
283
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
284
|
+
border-radius: 4px;
|
|
285
|
+
overflow: hidden;
|
|
286
|
+
background: var(--nice-bg-surface, #fff);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.nice-signature--disabled {
|
|
290
|
+
opacity: 0.6;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.nice-signature__toolbar {
|
|
294
|
+
display: flex;
|
|
295
|
+
align-items: center;
|
|
296
|
+
gap: 8px;
|
|
297
|
+
padding: 8px;
|
|
298
|
+
background: var(--nice-bg-muted, #f5f5f5);
|
|
299
|
+
border-bottom: 1px solid var(--nice-border, #e0e0e0);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.nice-signature__color-picker input {
|
|
303
|
+
width: 32px;
|
|
304
|
+
height: 32px;
|
|
305
|
+
padding: 2px;
|
|
306
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
307
|
+
border-radius: 4px;
|
|
308
|
+
cursor: pointer;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.nice-signature__size-slider {
|
|
312
|
+
flex: 1;
|
|
313
|
+
max-width: 120px;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.nice-signature__size-slider input {
|
|
317
|
+
width: 100%;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.nice-signature__actions {
|
|
321
|
+
display: flex;
|
|
322
|
+
gap: 4px;
|
|
323
|
+
margin-left: auto;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.nice-signature__btn {
|
|
327
|
+
padding: 6px 10px;
|
|
328
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
329
|
+
border-radius: 4px;
|
|
330
|
+
background: var(--nice-bg-surface, #fff);
|
|
331
|
+
cursor: pointer;
|
|
332
|
+
font-size: 14px;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.nice-signature__btn:hover:not(:disabled) {
|
|
336
|
+
background: var(--nice-bg-hover, #f0f0f0);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.nice-signature__btn:disabled {
|
|
340
|
+
opacity: 0.4;
|
|
341
|
+
cursor: not-allowed;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.nice-signature__canvas-wrapper {
|
|
345
|
+
position: relative;
|
|
346
|
+
background: #fff;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.nice-signature__canvas {
|
|
350
|
+
display: block;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
.nice-signature__placeholder {
|
|
354
|
+
position: absolute;
|
|
355
|
+
top: 50%;
|
|
356
|
+
left: 50%;
|
|
357
|
+
transform: translate(-50%, -50%);
|
|
358
|
+
color: var(--nice-text-secondary, #999);
|
|
359
|
+
font-size: 14px;
|
|
360
|
+
pointer-events: none;
|
|
361
|
+
user-select: none;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.nice-signature__line {
|
|
365
|
+
position: absolute;
|
|
366
|
+
bottom: 30px;
|
|
367
|
+
left: 20px;
|
|
368
|
+
right: 20px;
|
|
369
|
+
height: 1px;
|
|
370
|
+
background: var(--nice-border, #ccc);
|
|
371
|
+
pointer-events: none;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* Display component */
|
|
375
|
+
.nice-signature-display {
|
|
376
|
+
border: 1px solid var(--nice-border, #e0e0e0);
|
|
377
|
+
border-radius: 4px;
|
|
378
|
+
overflow: hidden;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
.nice-signature-display__canvas-wrapper {
|
|
382
|
+
position: relative;
|
|
383
|
+
background: #fff;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.nice-signature-display__canvas {
|
|
387
|
+
display: block;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.nice-signature-display__placeholder {
|
|
391
|
+
position: absolute;
|
|
392
|
+
top: 50%;
|
|
393
|
+
left: 50%;
|
|
394
|
+
transform: translate(-50%, -50%);
|
|
395
|
+
color: var(--nice-text-secondary, #999);
|
|
396
|
+
font-size: 14px;
|
|
397
|
+
}
|
|
398
|
+
`,document.head.appendChild(n)}const oa={strokeColor:"#ff3333",fillColor:"transparent",strokeWidth:2,opacity:1,fontSize:16,fontFamily:"sans-serif"};function ca(n,t){switch(t.type){case"SET_TOOL":return{...n,activeTool:t.tool,selectedId:null};case"SET_STYLE":return{...n,style:{...n.style,...t.style}};case"ADD_ANNOTATION":return{...n,annotations:[...n.annotations,t.annotation],past:[...n.past,n.annotations],future:[]};case"UPDATE_ANNOTATION":return{...n,annotations:n.annotations.map(i=>i.id===t.id?{...i,...t.updates}:i),past:[...n.past,n.annotations],future:[]};case"DELETE_ANNOTATION":return{...n,annotations:n.annotations.filter(i=>i.id!==t.id),selectedId:n.selectedId===t.id?null:n.selectedId,past:[...n.past,n.annotations],future:[]};case"SELECT":return{...n,selectedId:t.id};case"SET_ANNOTATIONS":return{...n,annotations:t.annotations,past:[],future:[]};case"SET_ZOOM":return{...n,zoom:t.zoom};case"SET_PAN":return{...n,panX:t.panX,panY:t.panY};case"UNDO":{if(n.past.length===0)return n;const i=n.past[n.past.length-1];return{...n,annotations:i,past:n.past.slice(0,-1),future:[n.annotations,...n.future]}}case"REDO":{if(n.future.length===0)return n;const i=n.future[0];return{...n,annotations:i,past:[...n.past,n.annotations],future:n.future.slice(1)}}case"CLEAR":return{...n,annotations:[],selectedId:null,past:[...n.past,n.annotations],future:[]};default:return n}}let da=0;function ua(){return`ann-${Date.now()}-${da++}`}function pa(n){const{style:t}=n,i=`stroke="${t.strokeColor}" stroke-width="${t.strokeWidth}" fill="${t.fillColor}" opacity="${t.opacity}"`;switch(n.tool){case"rectangle":return`<rect x="${n.x}" y="${n.y}" width="${n.width}" height="${n.height}" ${i} />`;case"ellipse":{const r=n.x+n.width/2,d=n.y+n.height/2;return`<ellipse cx="${r}" cy="${d}" rx="${n.width/2}" ry="${n.height/2}" ${i} />`}case"arrow":{const r=n,d=Math.atan2(r.endY-r.y,r.endX-r.x),f=12,_=r.endX-f*Math.cos(d-Math.PI/6),M=r.endY-f*Math.sin(d-Math.PI/6),N=r.endX-f*Math.cos(d+Math.PI/6),z=r.endY-f*Math.sin(d+Math.PI/6);return`<line x1="${r.x}" y1="${r.y}" x2="${r.endX}" y2="${r.endY}" ${i} />
|
|
399
|
+
<polygon points="${r.endX},${r.endY} ${_},${M} ${N},${z}" fill="${t.strokeColor}" opacity="${t.opacity}" />`}case"line":{const r=n;return`<line x1="${r.x}" y1="${r.y}" x2="${r.endX}" y2="${r.endY}" ${i} />`}case"text":{const r=n;return`<text x="${r.x}" y="${r.y+(r.style.fontSize??16)}" fill="${t.strokeColor}" font-size="${t.fontSize}" font-family="${t.fontFamily}" opacity="${t.opacity}">${ha(r.text)}</text>`}case"freehand":{const r=n;return r.points.length<2?"":`<path d="${r.points.map((d,f)=>`${f===0?"M":"L"}${d.x},${d.y}`).join(" ")}" ${i} fill="none" />`}case"blur":{const r=n,d=`blur-${r.id}`;return`<defs><filter id="${d}"><feGaussianBlur stdDeviation="${r.intensity??5}" /></filter></defs>
|
|
400
|
+
<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" fill="transparent" stroke="none" filter="url(#${d})" />`}default:return""}}function ha(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const mn=a.forwardRef(({src:n,alt:t="Annotatable image",annotations:i,activeTool:r,defaultStyle:d,onAnnotationsChange:f,className:_,readOnly:M=!1,minZoom:N=.1,maxZoom:z=5},V)=>{const H=a.useRef(null),g=a.useRef(null),k=a.useRef(null),[K,ee]=a.useState(!1),[X,S]=a.useState({width:0,height:0}),[v,I]=a.useReducer(ca,{annotations:i??[],selectedId:null,activeTool:r??"select",style:{...oa,...d},zoom:1,panX:0,panY:0,past:[],future:[]});a.useEffect(()=>{r&&I({type:"SET_TOOL",tool:r})},[r]),a.useEffect(()=>{f==null||f(v.annotations)},[v.annotations,f]),a.useEffect(()=>{const x=new Image;x.crossOrigin="anonymous",x.onload=()=>{k.current=x,S({width:x.naturalWidth,height:x.naturalHeight}),ee(!0)},x.src=n},[n]);const j=a.useRef({isDrawing:!1,startX:0,startY:0,currentAnnotation:null,freehandPoints:[]}),A=a.useCallback((x,p)=>{const R=H.current;if(!R)return{x:0,y:0};const y=R.getBoundingClientRect();return{x:(x-y.left-v.panX)/v.zoom,y:(p-y.top-v.panY)/v.zoom}},[v.zoom,v.panX,v.panY]),Y=a.useCallback(()=>{var u,s;const x=H.current,p=x==null?void 0:x.getContext("2d"),R=k.current;if(!x||!p||!R||!K)return;x.width=((u=g.current)==null?void 0:u.clientWidth)??R.naturalWidth,x.height=((s=g.current)==null?void 0:s.clientHeight)??R.naturalHeight,p.clearRect(0,0,x.width,x.height),p.save(),p.translate(v.panX,v.panY),p.scale(v.zoom,v.zoom),p.drawImage(R,0,0);for(const c of v.annotations){switch(p.save(),p.globalAlpha=c.style.opacity,p.strokeStyle=c.style.strokeColor,p.fillStyle=c.style.fillColor,p.lineWidth=c.style.strokeWidth,c.tool){case"rectangle":p.strokeRect(c.x,c.y,c.width,c.height),c.style.fillColor!=="transparent"&&p.fillRect(c.x,c.y,c.width,c.height);break;case"ellipse":{p.beginPath(),p.ellipse(c.x+c.width/2,c.y+c.height/2,Math.abs(c.width/2),Math.abs(c.height/2),0,0,Math.PI*2),p.stroke(),c.style.fillColor!=="transparent"&&p.fill();break}case"arrow":{const l=c;p.beginPath(),p.moveTo(l.x,l.y),p.lineTo(l.endX,l.endY),p.stroke();const o=Math.atan2(l.endY-l.y,l.endX-l.x),E=12;p.beginPath(),p.moveTo(l.endX,l.endY),p.lineTo(l.endX-E*Math.cos(o-Math.PI/6),l.endY-E*Math.sin(o-Math.PI/6)),p.lineTo(l.endX-E*Math.cos(o+Math.PI/6),l.endY-E*Math.sin(o+Math.PI/6)),p.closePath(),p.fillStyle=c.style.strokeColor,p.fill();break}case"line":{const l=c;p.beginPath(),p.moveTo(l.x,l.y),p.lineTo(l.endX,l.endY),p.stroke();break}case"text":{const l=c;p.font=`${l.style.fontSize??16}px ${l.style.fontFamily??"sans-serif"}`,p.fillStyle=l.style.strokeColor,p.fillText(l.text,l.x,l.y+(l.style.fontSize??16));break}case"freehand":{const l=c;if(l.points.length<2)break;p.beginPath(),p.moveTo(l.points[0].x,l.points[0].y);for(let o=1;o<l.points.length;o++)p.lineTo(l.points[o].x,l.points[o].y);p.stroke();break}case"blur":{const l=c;p.filter=`blur(${l.intensity??5}px)`,p.drawImage(R,l.x,l.y,l.width,l.height,l.x,l.y,l.width,l.height),p.filter="none";break}}c.id===v.selectedId&&(p.strokeStyle="#4488ff",p.lineWidth=1,p.setLineDash([4,4]),p.strokeRect(c.x-2,c.y-2,c.width+4,c.height+4),p.setLineDash([])),p.restore()}const y=j.current;if(y.isDrawing&&y.currentAnnotation){p.save();const c=y.currentAnnotation;if(p.globalAlpha=c.style.opacity,p.strokeStyle=c.style.strokeColor,p.lineWidth=c.style.strokeWidth,p.setLineDash([6,3]),c.tool==="freehand"){const l=c;if(l.points.length>=2){p.beginPath(),p.moveTo(l.points[0].x,l.points[0].y);for(let o=1;o<l.points.length;o++)p.lineTo(l.points[o].x,l.points[o].y);p.stroke()}}else if(c.tool==="rectangle")p.strokeRect(c.x,c.y,c.width,c.height);else if(c.tool==="ellipse")p.beginPath(),p.ellipse(c.x+c.width/2,c.y+c.height/2,Math.abs(c.width/2),Math.abs(c.height/2),0,0,Math.PI*2),p.stroke();else if(c.tool==="arrow"||c.tool==="line"){const l=c;p.beginPath(),p.moveTo(l.x,l.y),p.lineTo(l.endX,l.endY),p.stroke()}p.restore()}p.restore()},[v,K]);a.useEffect(()=>{Y()},[Y]);const b=a.useCallback(x=>{if(M)return;const p=A(x.clientX,x.clientY),R=v.activeTool;if(R==="select"){const s=[...v.annotations].reverse().find(c=>c.tool==="freehand"?!1:p.x>=c.x&&p.x<=c.x+c.width&&p.y>=c.y&&p.y<=c.y+c.height);I({type:"SELECT",id:(s==null?void 0:s.id)??null});return}const y=j.current;y.isDrawing=!0,y.startX=p.x,y.startY=p.y;const u={id:ua(),style:{...v.style},x:p.x,y:p.y,width:0,height:0};switch(R){case"rectangle":y.currentAnnotation={...u,tool:"rectangle"};break;case"ellipse":y.currentAnnotation={...u,tool:"ellipse"};break;case"arrow":y.currentAnnotation={...u,tool:"arrow",endX:p.x,endY:p.y};break;case"line":y.currentAnnotation={...u,tool:"line",endX:p.x,endY:p.y};break;case"text":y.currentAnnotation={...u,tool:"text",text:"Text",width:100,height:v.style.fontSize??16};break;case"freehand":y.freehandPoints=[p],y.currentAnnotation={...u,tool:"freehand",points:[p]};break;case"blur":y.currentAnnotation={...u,tool:"blur",intensity:5};break}},[M,A,v.activeTool,v.style,v.annotations]),h=a.useCallback(x=>{const p=j.current;if(!p.isDrawing||!p.currentAnnotation)return;const R=A(x.clientX,x.clientY),y=p.currentAnnotation;if(y.tool==="freehand"){p.freehandPoints.push(R),y.points=[...p.freehandPoints];const u=p.freehandPoints.map(c=>c.x),s=p.freehandPoints.map(c=>c.y);y.x=Math.min(...u),y.y=Math.min(...s),y.width=Math.max(...u)-y.x,y.height=Math.max(...s)-y.y}else if(y.tool==="arrow"||y.tool==="line")y.endX=R.x,y.endY=R.y,y.width=Math.abs(R.x-p.startX),y.height=Math.abs(R.y-p.startY);else{const u=Math.min(p.startX,R.x),s=Math.min(p.startY,R.y);y.x=u,y.y=s,y.width=Math.abs(R.x-p.startX),y.height=Math.abs(R.y-p.startY)}Y()},[A,Y]),C=a.useCallback(()=>{const x=j.current;if(!x.isDrawing||!x.currentAnnotation)return;const p=x.currentAnnotation;(p.tool==="text"||p.tool==="freehand"||Math.abs(p.width)>2||Math.abs(p.height)>2)&&I({type:"ADD_ANNOTATION",annotation:p}),x.isDrawing=!1,x.currentAnnotation=null,x.freehandPoints=[]},[]),w=a.useCallback(x=>{x.preventDefault();const p=x.deltaY>0?.9:1.1,R=Math.max(N,Math.min(z,v.zoom*p));I({type:"SET_ZOOM",zoom:R})},[v.zoom,N,z]);a.useEffect(()=>{if(M)return;const x=p=>{(p.metaKey||p.ctrlKey)&&p.key==="z"&&!p.shiftKey?(p.preventDefault(),I({type:"UNDO"})):(p.metaKey||p.ctrlKey)&&(p.key==="y"||p.key==="z"&&p.shiftKey)?(p.preventDefault(),I({type:"REDO"})):(p.key==="Delete"||p.key==="Backspace")&&v.selectedId&&I({type:"DELETE_ANNOTATION",id:v.selectedId})};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[M,v.selectedId]),a.useImperativeHandle(V,()=>({exportAsDataURL:async(x="png",p=.92)=>{const R=document.createElement("canvas"),y=k.current;if(!y)return"";R.width=y.naturalWidth,R.height=y.naturalHeight;const u=R.getContext("2d");u.drawImage(y,0,0);for(const s of v.annotations){if(u.save(),u.globalAlpha=s.style.opacity,u.strokeStyle=s.style.strokeColor,u.fillStyle=s.style.fillColor,u.lineWidth=s.style.strokeWidth,s.tool==="rectangle")u.strokeRect(s.x,s.y,s.width,s.height);else if(s.tool==="ellipse")u.beginPath(),u.ellipse(s.x+s.width/2,s.y+s.height/2,Math.abs(s.width/2),Math.abs(s.height/2),0,0,Math.PI*2),u.stroke();else if(s.tool==="freehand"){const c=s;if(c.points.length>=2){u.beginPath(),u.moveTo(c.points[0].x,c.points[0].y);for(let l=1;l<c.points.length;l++)u.lineTo(c.points[l].x,c.points[l].y);u.stroke()}}else if(s.tool==="text"){const c=s;u.font=`${c.style.fontSize??16}px ${c.style.fontFamily??"sans-serif"}`,u.fillStyle=c.style.strokeColor,u.fillText(c.text,c.x,c.y+(c.style.fontSize??16))}u.restore()}return R.toDataURL(`image/${x}`,p)},exportAnnotations:()=>[...v.annotations],importAnnotations:x=>{I({type:"SET_ANNOTATIONS",annotations:x})},exportAsSVG:()=>{const{width:x,height:p}=X,R=v.annotations.map(pa);return`<svg xmlns="http://www.w3.org/2000/svg" width="${x}" height="${p}" viewBox="0 0 ${x} ${p}">
|
|
401
|
+
${R.join(`
|
|
402
|
+
`)}
|
|
403
|
+
</svg>`},undo:()=>I({type:"UNDO"}),redo:()=>I({type:"REDO"}),setZoom:x=>{I({type:"SET_ZOOM",zoom:Math.max(N,Math.min(z,x))})},fitToScreen:()=>{const x=g.current,p=k.current;if(!x||!p)return;const R=x.clientWidth/p.naturalWidth,y=x.clientHeight/p.naturalHeight,u=Math.min(R,y,1);I({type:"SET_ZOOM",zoom:u}),I({type:"SET_PAN",panX:0,panY:0})},clear:()=>I({type:"CLEAR"})}),[v.annotations,X,N,z]);const O=a.useCallback(x=>{if(x.touches.length!==1)return;const p=x.touches[0];b({clientX:p.clientX,clientY:p.clientY,preventDefault:()=>{}})},[b]),L=a.useCallback(x=>{if(x.touches.length!==1)return;const p=x.touches[0];h({clientX:p.clientX,clientY:p.clientY})},[h]);return e.jsx("div",{ref:g,className:`nice-image-annotator ${_??""}`,style:{position:"relative",overflow:"hidden",width:"100%",height:"100%"},children:e.jsx("canvas",{ref:H,className:"nice-image-annotator__canvas",style:{cursor:v.activeTool==="select"?"default":"crosshair"},onMouseDown:b,onMouseMove:h,onMouseUp:C,onMouseLeave:C,onWheel:w,onTouchStart:O,onTouchMove:L,onTouchEnd:C,role:"img","aria-label":t})})});mn.displayName="NiceImageAnnotator";function ma(n){let t=n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return t=t.replace(/```(\w*)\n([\s\S]*?)```/g,(i,r,d)=>`<pre><code class="language-${r}">${d.trim()}</code></pre>`),t=t.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(i,r,d,f)=>{const _=r.split("|").filter(N=>N.trim()).map(N=>`<th>${N.trim()}</th>`).join(""),M=f.trim().split(`
|
|
404
|
+
`).map(N=>`<tr>${N.split("|").filter(z=>z.trim()).map(z=>`<td>${z.trim()}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${_}</tr></thead><tbody>${M}</tbody></table>`}),t=t.replace(/^#### (.+)$/gm,"<h4>$1</h4>"),t=t.replace(/^### (.+)$/gm,"<h3>$1</h3>"),t=t.replace(/^## (.+)$/gm,"<h2>$1</h2>"),t=t.replace(/^# (.+)$/gm,"<h1>$1</h1>"),t=t.replace(/^> (.+)$/gm,"<blockquote>$1</blockquote>"),t=t.replace(/^---$/gm,"<hr/>"),t=t.replace(/^- \[x\] (.+)$/gm,'<li class="task done">☑ $1</li>'),t=t.replace(/^- \[ \] (.+)$/gm,'<li class="task">☐ $1</li>'),t=t.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/~~(.+?)~~/g,"<del>$1</del>"),t=t.replace(/`(.+?)`/g,"<code>$1</code>"),t=t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" style="max-width:100%"/>'),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2">$1</a>'),t=t.replace(/^\- (.+)$/gm,"<li>$1</li>"),t=t.replace(/^\d+\. (.+)$/gm,"<li>$1</li>"),t=t.replace(/\n/g,"<br/>"),t}const ga=[{key:"bold",label:"B",md:"**",tip:"Bold",shortcut:"Ctrl+B",group:"format"},{key:"italic",label:"I",md:"*",tip:"Italic",shortcut:"Ctrl+I",group:"format"},{key:"strike",label:"S̶",md:"~~",tip:"Strikethrough",group:"format"},{key:"code",label:"< >",md:"`",tip:"Inline code",group:"format"},{key:"h1",label:"H1",md:"# ",tip:"Heading 1",group:"heading"},{key:"h2",label:"H2",md:"## ",tip:"Heading 2",group:"heading"},{key:"h3",label:"H3",md:"### ",tip:"Heading 3",group:"heading"},{key:"ul",label:"•",md:"- ",tip:"Unordered list",group:"list"},{key:"ol",label:"1.",md:"1. ",tip:"Ordered list",group:"list"},{key:"task",label:"☑",md:"- [ ] ",tip:"Task list",group:"list"},{key:"quote",label:"❝",md:"> ",tip:"Blockquote",group:"block"},{key:"hr",label:"—",md:`---
|
|
405
|
+
`,tip:"Horizontal rule",group:"block"},{key:"link",label:"🔗",md:"[](url)",tip:"Link",shortcut:"Ctrl+K",group:"insert"},{key:"image",label:"🖼",md:"",tip:"Image",group:"insert"},{key:"table",label:"⊞",md:`| H1 | H2 | H3 |
|
|
406
|
+
| --- | --- | --- |
|
|
407
|
+
| c1 | c2 | c3 |
|
|
408
|
+
`,tip:"Table",group:"insert"},{key:"codeblock",label:"```",md:"```\n",tip:"Code block",group:"insert"}],fa=["format","heading","list","block","insert"],gn=a.forwardRef(({value:n="",onChange:t,preview:i="side",placeholder:r,disabled:d,readOnly:f,size:_="md",editorSize:M="standard",toolbar:N=!0,minHeight:z=200,showWordCount:V=!1,showLineNumbers:H=!1,onExportHtml:g,onImageUpload:k,className:K,style:ee,id:X},S)=>{const v=F.Os(X),[I,j]=a.useState("edit"),[A,Y]=a.useState(!1),b=a.useRef(null),h=a.useMemo(()=>ma(n),[n]),C=a.useMemo(()=>{const y=n.trim()?n.trim().split(/\s+/).length:0,u=n.length,s=n.split(`
|
|
409
|
+
`).length;return{words:y,chars:u,lines:s}},[n]),w=a.useCallback(y=>{const u=b.current;if(!u)return;const s=u.selectionStart,c=u.selectionEnd,l=n.slice(s,c);let o,E;y==="[](url)"?(o=n.slice(0,s)+`[${l||"text"}](url)`+n.slice(c),E=s+1+(l||"text").length+2):y===""?(o=n.slice(0,s)+``+n.slice(c),E=s+2+(l||"alt").length+2):y.endsWith(`
|
|
410
|
+
`)||y.endsWith(" ")?(o=n.slice(0,s)+y+l+n.slice(c),E=s+y.length+l.length):(o=n.slice(0,s)+y+l+y+n.slice(c),E=s+y.length+l.length+y.length),t==null||t(o),requestAnimationFrame(()=>{u.focus(),u.setSelectionRange(E,E)})},[n,t]),O=a.useCallback(y=>{if((y.ctrlKey||y.metaKey)&&(y.key==="b"?(y.preventDefault(),w("**")):y.key==="i"?(y.preventDefault(),w("*")):y.key==="k"&&(y.preventDefault(),w("[](url)"))),y.key==="Tab"){y.preventDefault();const u=y.currentTarget,s=u.selectionStart,c=u.selectionEnd,l=" ";if(y.shiftKey){const o=n.slice(0,s).lastIndexOf(`
|
|
411
|
+
`)+1;if(n.slice(o,o+l.length)===l){const E=n.slice(0,o)+n.slice(o+l.length);t==null||t(E),requestAnimationFrame(()=>{u.selectionStart=u.selectionEnd=s-l.length})}}else{const o=n.slice(0,s)+l+n.slice(c);t==null||t(o),requestAnimationFrame(()=>{u.selectionStart=u.selectionEnd=s+l.length})}}},[n,t,w]),L=a.useCallback(async y=>{if(!k)return;const u=Array.from(y.dataTransfer.files).filter(s=>s.type.startsWith("image/"));if(u.length!==0){y.preventDefault();for(const s of u){const c=await k(s),l=b.current;if(!l)continue;const o=l.selectionStart,E=`
|
|
412
|
+
`,J=n.slice(0,o)+E+n.slice(o);t==null||t(J)}}},[n,t,k]),x=i!=="tab"||I==="edit",p=i==="side"||i==="tab"&&I==="preview"||i===!0,R=`nice-md-editor nice-md-editor--${_} nice-editor--${M} nice-md-editor--preview-${i}${A?" nice-md-editor--fullscreen":""} ${K||""}`;return e.jsxs("div",{ref:S,id:v,className:R,style:ee,children:[N&&e.jsxs("div",{className:"nice-md-editor__toolbar",children:[fa.map((y,u)=>e.jsxs(a.Fragment,{children:[u>0&&e.jsx("span",{className:"nice-md-editor__sep"}),ga.filter(s=>s.group===y).map(s=>e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:s.shortcut?`${s.tip} (${s.shortcut})`:s.tip,disabled:d||f,onClick:()=>w(s.md),children:s.label},s.key))]},y)),e.jsx("span",{className:"nice-md-editor__sep"}),e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:"Fullscreen",onClick:()=>Y(!A),children:A?"⊙":"⛶"}),g&&e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:"Export HTML",onClick:()=>g(h),children:"↗"}),i==="tab"&&e.jsxs("span",{className:"nice-md-editor__tabs",children:[e.jsx("button",{type:"button",className:`nice-md-editor__tab${I==="edit"?" nice-md-editor__tab--active":""}`,onClick:()=>j("edit"),children:"Edit"}),e.jsx("button",{type:"button",className:`nice-md-editor__tab${I==="preview"?" nice-md-editor__tab--active":""}`,onClick:()=>j("preview"),children:"Preview"})]})]}),e.jsxs("div",{className:"nice-md-editor__body",style:{minHeight:z},children:[x&&e.jsxs("div",{className:"nice-md-editor__editor-wrap",children:[H&&e.jsx("div",{className:"nice-md-editor__line-numbers",children:Array.from({length:C.lines},(y,u)=>e.jsx("div",{className:"nice-md-editor__line-no",children:u+1},u))}),e.jsx("textarea",{ref:b,className:"nice-md-editor__textarea",value:n,onChange:y=>t==null?void 0:t(y.target.value),onKeyDown:O,onDrop:L,placeholder:r,disabled:d,readOnly:f,style:{minHeight:z}})]}),p&&e.jsx("div",{className:"nice-md-editor__preview",dangerouslySetInnerHTML:{__html:F.Ts(h)},style:{minHeight:z}})]}),V&&e.jsxs("div",{className:"nice-md-editor__statusbar",children:[e.jsxs("span",{children:[C.words," words"]}),e.jsxs("span",{children:[C.chars," chars"]}),e.jsxs("span",{children:[C.lines," lines"]})]})]})});gn.displayName="NiceMarkdownEditor";const Bt={rotation:0,flipH:!1,flipV:!1,brightness:100,contrast:100,saturate:100,blur:0,crop:null,annotations:[]},ba=["crop","rotate","flip","brightness","contrast","saturate","blur","annotate"],fn=a.forwardRef(({src:n,size:t="md",editorSize:i="standard",tools:r=ba,showToolbar:d=!0,showZoom:f=!0,maxUndo:_=30,onSave:M,onCancel:N,onChange:z,width:V="100%",height:H=500,className:g,style:k,id:K,...ee},X)=>{const S=F.Os(K),{t:v}=F.ue(),I=a.useRef(null),j=a.useRef(null),[A,Y]=a.useState({...Bt}),[b,h]=a.useState(null),[C,w]=a.useState(!1),[O,L]=a.useState(1),[x,p]=a.useState("rect"),[R,y]=a.useState("#ff0000"),[u,s]=a.useState({w:0,h:0}),[c,l]=a.useState([]),[o,E]=a.useState([]),[J,te]=a.useState(null),[q,$]=a.useState(null),[P,W]=a.useState(null),le=a.useCallback(D=>{l(T=>[...T.slice(-(_-1)),D]),E([])},[_]),re=a.useCallback(D=>{Y(T=>{le(T);const ae={...T,...D};return z==null||z(ae),ae})},[z,le]),pe=a.useCallback(()=>{if(c.length===0)return;const D=c[c.length-1];l(T=>T.slice(0,-1)),E(T=>[...T,A]),Y(D),z==null||z(D)},[c,A,z]),me=a.useCallback(()=>{if(o.length===0)return;const D=o[o.length-1];E(T=>T.slice(0,-1)),l(T=>[...T,A]),Y(D),z==null||z(D)},[o,A,z]);a.useEffect(()=>{const D=new Image;D.crossOrigin="anonymous",D.onload=()=>{j.current=D,s({w:D.width,h:D.height}),w(!0)},D.src=n},[n]),a.useEffect(()=>{if(!C||!I.current||!j.current)return;const D=I.current,T=D.getContext("2d");if(!T)return;const ae=j.current,Q=A.rotation%180!==0,B=Q?ae.height:ae.width,ie=Q?ae.width:ae.height;D.width=B,D.height=ie,T.clearRect(0,0,B,ie),T.save(),T.filter=`brightness(${A.brightness}%) contrast(${A.contrast}%) saturate(${A.saturate}%) blur(${A.blur}px)`,T.translate(B/2,ie/2),T.rotate(A.rotation*Math.PI/180),T.scale(A.flipH?-1:1,A.flipV?-1:1),T.drawImage(ae,-ae.width/2,-ae.height/2),T.restore(),A.annotations.forEach(oe=>{switch(T.save(),T.strokeStyle=oe.color??"red",T.fillStyle=oe.color??"red",T.lineWidth=oe.strokeWidth??2,T.font=`${oe.fontSize??16}px sans-serif`,oe.type){case"text":T.fillText(oe.text??"",oe.x,oe.y);break;case"rect":T.strokeRect(oe.x,oe.y,oe.width??100,oe.height??50);break;case"circle":{const ke=(oe.width??50)/2,ge=(oe.height??50)/2;T.beginPath(),T.ellipse(oe.x+ke,oe.y+ge,ke,ge,0,0,Math.PI*2),T.stroke();break}case"line":T.beginPath(),T.moveTo(oe.x,oe.y),T.lineTo(oe.x+(oe.width??100),oe.y+(oe.height??0)),T.stroke();break;case"arrow":{const ke=oe.x+(oe.width??100),ge=oe.y+(oe.height??0);T.beginPath(),T.moveTo(oe.x,oe.y),T.lineTo(ke,ge),T.stroke();const ye=Math.atan2(ge-oe.y,ke-oe.x),Me=10;T.beginPath(),T.moveTo(ke,ge),T.lineTo(ke-Me*Math.cos(ye-.4),ge-Me*Math.sin(ye-.4)),T.lineTo(ke-Me*Math.cos(ye+.4),ge-Me*Math.sin(ye+.4)),T.closePath(),T.fill();break}}T.restore()}),q&&(T.save(),T.fillStyle="rgba(0,0,0,0.5)",T.fillRect(0,0,B,ie),T.clearRect(q.x,q.y,q.w,q.h),T.strokeStyle="var(--bg-primary, #fff)",T.lineWidth=2,T.setLineDash([5,5]),T.strokeRect(q.x,q.y,q.w,q.h),T.restore())},[C,A,q]);const Ne=a.useCallback(D=>{if(!I.current)return;const T=I.current.getBoundingClientRect(),ae=I.current.width/T.width,Q=I.current.height/T.height,B=(D.clientX-T.left)*ae,ie=(D.clientY-T.top)*Q;b==="crop"?te({startX:B,startY:ie}):b==="annotate"&&W({startX:B,startY:ie})},[b]),ne=a.useCallback(D=>{if(!I.current)return;const T=I.current.getBoundingClientRect(),ae=I.current.width/T.width,Q=I.current.height/T.height,B=(D.clientX-T.left)*ae,ie=(D.clientY-T.top)*Q;J&&$({x:Math.min(J.startX,B),y:Math.min(J.startY,ie),w:Math.abs(B-J.startX),h:Math.abs(ie-J.startY)})},[J]),de=a.useCallback(D=>{if(J&&q&&q.w>5&&q.h>5&&re({crop:{x:q.x,y:q.y,width:q.w,height:q.h}}),te(null),P&&I.current){const T=I.current.getBoundingClientRect(),ae=I.current.width/T.width,Q=I.current.height/T.height,B=(D.clientX-T.left)*ae,ie=(D.clientY-T.top)*Q,oe=B-P.startX,ke=ie-P.startY;if(Math.abs(oe)>3||Math.abs(ke)>3||x==="text"){const ge={type:x,x:P.startX,y:P.startY,width:Math.abs(oe)||100,height:Math.abs(ke)||50,color:R,strokeWidth:2,text:x==="text"?prompt(v("imageEditor.annotationText","Text:"))??"":void 0};re({annotations:[...A.annotations,ge]})}W(null)}},[J,q,P,x,R,A.annotations,re,v]),ue=a.useCallback(()=>{if(!A.crop||!I.current)return;const D=I.current,T=D.getContext("2d");if(!T)return;const{x:ae,y:Q,width:B,height:ie}=A.crop,oe=T.getImageData(ae,Q,B,ie);D.width=B,D.height=ie,T.putImageData(oe,0,0),$(null),h(null)},[A.crop]),ve=a.useCallback(()=>{if(!I.current)return;const D=I.current.toDataURL("image/png");M==null||M(D,A)},[M,A]),se=a.useCallback(()=>{Y({...Bt}),$(null),h(null)},[]);return a.useMemo(()=>`brightness(${A.brightness}%) contrast(${A.contrast}%) saturate(${A.saturate}%) blur(${A.blur}px)`,[A.brightness,A.contrast,A.saturate,A.blur]),e.jsxs("div",{ref:X,id:S,className:`nice-image-editor nice-image-editor--${t} nice-editor--${i} ${g??""}`,style:{...k,width:V,height:H},role:"application","aria-label":v("imageEditor.label","Image Editor"),...ee,children:[d&&e.jsxs("div",{className:"nice-image-editor__toolbar",role:"toolbar",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:pe,disabled:c.length===0,title:v("imageEditor.undo","Undo"),children:"↶"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:me,disabled:o.length===0,title:v("imageEditor.redo","Redo"),children:"↷"}),e.jsx("span",{className:"nice-image-editor__sep"}),r.includes("rotate")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({rotation:(A.rotation-90+360)%360}),title:v("imageEditor.rotateLeft","Rotate left"),children:"↺"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({rotation:(A.rotation+90)%360}),title:v("imageEditor.rotateRight","Rotate right"),children:"↻"})]}),r.includes("flip")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({flipH:!A.flipH}),title:v("imageEditor.flipH","Flip horizontal"),children:"⇔"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({flipV:!A.flipV}),title:v("imageEditor.flipV","Flip vertical"),children:"⇕"})]}),r.includes("crop")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:`nice-image-editor__btn ${b==="crop"?"nice-image-editor__btn--active":""}`,onClick:()=>h(b==="crop"?null:"crop"),title:v("imageEditor.crop","Crop"),children:"⊡"}),b==="crop"&&A.crop&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:ue,title:v("imageEditor.applyCrop","Apply crop"),children:"✓"})]}),r.includes("brightness")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[v("imageEditor.brightness","☀"),e.jsx("input",{type:"range",min:0,max:200,value:A.brightness,onChange:D=>re({brightness:Number(D.target.value)}),className:"nice-image-editor__slider",title:v("imageEditor.brightness","Brightness")})]}),r.includes("contrast")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[v("imageEditor.contrast","◑"),e.jsx("input",{type:"range",min:0,max:200,value:A.contrast,onChange:D=>re({contrast:Number(D.target.value)}),className:"nice-image-editor__slider",title:v("imageEditor.contrast","Contrast")})]}),r.includes("saturate")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[v("imageEditor.saturate","🎨"),e.jsx("input",{type:"range",min:0,max:200,value:A.saturate,onChange:D=>re({saturate:Number(D.target.value)}),className:"nice-image-editor__slider",title:v("imageEditor.saturate","Saturation")})]}),r.includes("blur")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[v("imageEditor.blur","⊘"),e.jsx("input",{type:"range",min:0,max:20,step:.5,value:A.blur,onChange:D=>re({blur:Number(D.target.value)}),className:"nice-image-editor__slider",title:v("imageEditor.blur","Blur")})]}),r.includes("annotate")&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:`nice-image-editor__btn ${b==="annotate"?"nice-image-editor__btn--active":""}`,onClick:()=>h(b==="annotate"?null:"annotate"),title:v("imageEditor.annotate","Annotate"),children:"✎"}),b==="annotate"&&e.jsxs(e.Fragment,{children:[e.jsxs("select",{className:"nice-image-editor__select",value:x,onChange:D=>p(D.target.value),children:[e.jsx("option",{value:"rect",children:"□ Rect"}),e.jsx("option",{value:"circle",children:"○ Circle"}),e.jsx("option",{value:"line",children:"╱ Line"}),e.jsx("option",{value:"arrow",children:"→ Arrow"}),e.jsx("option",{value:"text",children:"T Text"})]}),e.jsx("input",{type:"color",value:R,onChange:D=>y(D.target.value),className:"nice-image-editor__color",title:v("imageEditor.color","Color")}),A.annotations.length>0&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({annotations:A.annotations.slice(0,-1)}),title:v("imageEditor.removeLastAnnotation","Remove last"),children:"⌫"})]})]}),e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:se,title:v("imageEditor.reset","Reset"),children:"⟲"}),M&&e.jsx("button",{type:"button",className:"nice-image-editor__btn nice-image-editor__btn--save",onClick:ve,children:v("imageEditor.save","Save")}),N&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:N,children:v("imageEditor.cancel","Cancel")})]}),e.jsx("div",{className:"nice-image-editor__canvas-wrap",children:e.jsx("canvas",{ref:I,className:"nice-image-editor__canvas",onMouseDown:Ne,onMouseMove:ne,onMouseUp:de,style:{cursor:b==="crop"||b==="annotate"?"crosshair":"default",transform:`scale(${O})`,transformOrigin:"center center"}})}),f&&e.jsxs("div",{className:"nice-image-editor__footer",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>L(D=>Math.max(.1,D-.1)),title:"Zoom out",children:"−"}),e.jsxs("span",{style:{fontSize:"0.85em",minWidth:40,textAlign:"center"},children:[Math.round(O*100),"%"]}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>L(D=>Math.min(5,D+.1)),title:"Zoom in",children:"+"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>L(1),title:"Reset zoom",children:"1:1"}),e.jsx("span",{style:{flex:1}}),e.jsxs("span",{style:{fontSize:"0.8em",color:"var(--nice-text-secondary, #666)"},children:[u.w,"×",u.h,"px · ",A.rotation,"°"]})]})]})});fn.displayName="NiceImageEditor";const bn=a.forwardRef(({value:n,onChange:t,penColor:i="var(--text-primary, #000)",penWidth:r=2,backgroundColor:d="var(--bg-primary, #fff)",width:f=400,height:_=200,size:M="md",disabled:N=!1,readOnly:z=!1,showClear:V=!0,showUndo:H=!0,label:g,exportFormat:k="image/png",className:K,style:ee,id:X,...S},v)=>{const I=F.Os(X),{t:j}=F.ue(),A=a.useRef(null),[Y,b]=a.useState(!1),h=a.useRef([]),C=a.useRef([]),[w,O]=a.useState(!0),L=a.useCallback(()=>{const c=A.current;if(!c)return;const l=c.getContext("2d");if(l){l.fillStyle=d,l.fillRect(0,0,c.width,c.height),l.strokeStyle=i,l.lineWidth=r,l.lineCap="round",l.lineJoin="round";for(const o of h.current)if(!(o.length<2)){l.beginPath(),l.moveTo(o[0].x,o[0].y);for(let E=1;E<o.length;E++)l.lineTo(o[E].x,o[E].y);l.stroke()}}},[d,i,r]);a.useEffect(()=>{if(n&&A.current){const c=new Image;c.onload=()=>{var o;const l=(o=A.current)==null?void 0:o.getContext("2d");!l||!A.current||(l.fillStyle=d,l.fillRect(0,0,A.current.width,A.current.height),l.drawImage(c,0,0),O(!1))},c.src=n}else n||(h.current=[],O(!0),L())},[n,d,L]),a.useEffect(()=>{const c=A.current;c&&(c.width=f,c.height=_,L())},[f,_,L]);const x=a.useCallback(c=>{const l=A.current,o=l.getBoundingClientRect(),E=l.width/o.width,J=l.height/o.height;if("touches"in c){const te=c.touches[0];return{x:(te.clientX-o.left)*E,y:(te.clientY-o.top)*J}}return{x:(c.clientX-o.left)*E,y:(c.clientY-o.top)*J}},[]),p=a.useCallback(c=>{if(N||z)return;c.preventDefault();const l=x(c);C.current=[l],b(!0)},[N,z,x]),R=a.useCallback(c=>{if(!Y)return;c.preventDefault();const l=x(c);C.current.push(l);const o=A.current,E=o==null?void 0:o.getContext("2d");if(!E||!o)return;const J=C.current;J.length>=2&&(E.strokeStyle=i,E.lineWidth=r,E.lineCap="round",E.beginPath(),E.moveTo(J[J.length-2].x,J[J.length-2].y),E.lineTo(l.x,l.y),E.stroke())},[Y,x,i,r]),y=a.useCallback(()=>{if(Y&&(b(!1),C.current.length>0&&(h.current.push([...C.current]),C.current=[],O(!1),A.current))){const c=A.current.toDataURL(k);t==null||t(c)}},[Y,k,t]),u=a.useCallback(()=>{h.current=[],C.current=[],O(!0),L(),t==null||t(null)},[L,t]),s=a.useCallback(()=>{if(h.current.length!==0&&(h.current.pop(),O(h.current.length===0),L(),A.current)){const c=h.current.length>0?A.current.toDataURL(k):null;t==null||t(c)}},[L,k,t]);return e.jsxs("div",{ref:v,id:I,className:`nice-signature nice-signature--${M} ${N?"nice-signature--disabled":""} ${z?"nice-signature--readonly":""} ${K??""}`,style:ee,...S,children:[g&&e.jsx("label",{className:"nice-signature__label",children:g}),e.jsx("div",{className:"nice-signature__canvas-wrap",style:{width:f,height:_},children:e.jsx("canvas",{ref:A,className:"nice-signature__canvas",onMouseDown:p,onMouseMove:R,onMouseUp:y,onMouseLeave:y,onTouchStart:p,onTouchMove:R,onTouchEnd:y,style:{touchAction:"none",cursor:N||z?"default":"crosshair"},"aria-label":g??j("signature.label","Signature pad"),role:"img"})}),(V||H)&&!z&&!N&&e.jsxs("div",{className:"nice-signature__actions",children:[H&&e.jsx("button",{type:"button",className:"nice-signature__btn",onClick:s,disabled:w,children:j("signature.undo","Undo")}),V&&e.jsx("button",{type:"button",className:"nice-signature__btn",onClick:u,disabled:w,children:j("signature.clear","Clear")})]})]})});bn.displayName="NiceSignaturePad";let xa=0;function jt(){return`blk-${++xa}-${Date.now().toString(36)}`}function Vt(n=""){return{id:jt(),type:"paragraph",content:n}}function ya(n,t=""){const i={id:jt(),type:n,content:t};return n==="heading"&&(i.level=2),n==="list"&&(i.listType="unordered"),n==="callout"&&(i.icon="??"),n==="toggle"&&(i.open=!0),i}const _a=[{type:"paragraph",label:"Text",icon:"�",keywords:"paragraph text"},{type:"heading",label:"Heading",icon:"H",keywords:"heading title"},{type:"list",label:"Bulleted list",icon:"�",keywords:"bullet unordered list"},{type:"list",label:"Numbered list",icon:"1.",keywords:"numbered ordered list"},{type:"list",label:"Checklist",icon:"?",keywords:"check todo list"},{type:"quote",label:"Quote",icon:"?",keywords:"quote blockquote"},{type:"callout",label:"Callout",icon:"??",keywords:"callout info alert"},{type:"toggle",label:"Toggle",icon:"?",keywords:"toggle collapse expand"},{type:"code",label:"Code",icon:"</>",keywords:"code snippet"},{type:"image",label:"Image",icon:"??",keywords:"image photo picture"},{type:"video",label:"Video",icon:"??",keywords:"video embed"},{type:"table",label:"Table",icon:"?",keywords:"table grid"},{type:"divider",label:"Divider",icon:"-",keywords:"divider line separator"},{type:"pageBreak",label:"Page Break",icon:"?",keywords:"page break"}];function va(n){const t=[n.align?`text-align:${n.align}`:"",n.color?`color:${n.color}`:"",n.bgColor?`background-color:${n.bgColor}`:"",n.indent?`margin-left:${n.indent*24}px`:""].filter(Boolean).join(";"),i=t?` style="${t}"`:"",r=(d,f)=>{let _=f;return n.bold&&(_=`<strong>${_}</strong>`),n.italic&&(_=`<em>${_}</em>`),n.underline&&(_=`<u>${_}</u>`),n.strikethrough&&(_=`<s>${_}</s>`),`<${d}${i}>${_}</${d}>`};switch(n.type){case"heading":return r(`h${n.level??2}`,n.content);case"paragraph":return r("p",n.content||" ");case"list":{const d=n.listType==="ordered"?"ol":"ul",f=n.content.split(`
|
|
413
|
+
`).map((_,M)=>{var N;return n.listType==="checklist"?`<li><input type="checkbox" ${((N=n.checked)==null?void 0:N[M])??!1?"checked":""} disabled />${_}</li>`:`<li>${_}</li>`}).join("");return`<${d}${i}>${f}</${d}>`}case"image":return`<figure${i}><img src="${n.src??""}" alt="${n.alt??""}" /></figure>`;case"video":return`<figure${i}><video src="${n.src??""}" controls></video></figure>`;case"divider":return"<hr />";case"pageBreak":return'<div style="page-break-after:always"></div>';case"code":return`<pre><code class="language-${n.language??""}">${n.content}</code></pre>`;case"quote":return r("blockquote",n.content);case"callout":return`<div class="nice-doc-callout"${i}><span>${n.icon??"??"}</span><div>${n.content}</div></div>`;case"toggle":return`<details${i}><summary>${n.content.split(`
|
|
414
|
+
`)[0]}</summary>${n.content.split(`
|
|
415
|
+
`).slice(1).join("<br>")}</details>`;case"table":return`<table${i}>${n.content}</table>`;case"embed":return`<iframe src="${n.src??""}" style="width:100%;border:none;min-height:300px"></iframe>`;default:return r("p",n.content)}}function ka(n){let t=0,i=0;for(const r of n){const d=r.content??"";t+=d.length;const f=d.trim().split(/\s+/).filter(Boolean);i+=f.length}return{words:i,chars:t,readingTime:Math.max(1,Math.ceil(i/200))}}const xn=a.forwardRef(({blocks:n,onChange:t,readOnly:i=!1,showToolbar:r=!0,size:d="md",editorSize:f="standard",placeholder:_,onExport:M,onImageUpload:N,maxUndo:z=50,slashCommands:V=!0,showWordCount:H=!1,showToc:g=!1,showFindReplace:k=!0,className:K,style:ee,id:X,...S},v)=>{var ce,he,_e,be,we,xe,Ie,Te,Re,Ae,Qe,Oe,Ge,Ct,Nt,wt;const I=F.Os(X),{t:j}=F.ue(),[A,Y]=a.useState(()=>n??[Vt()]),b=n??A,[h,C]=a.useState(0),w=a.useRef(new Map),O=a.useRef(null),[L,x]=a.useState(!1),[p,R]=a.useState(""),[y,u]=a.useState(""),[s,c]=a.useState([]),[l,o]=a.useState(0),[E,J]=a.useState(!1),te=a.useRef([]),q=a.useRef([]),$=a.useCallback(m=>{te.current.push(m.map(G=>({...G,checked:G.checked?[...G.checked]:void 0}))),te.current.length>z&&te.current.shift(),q.current=[]},[z]),P=a.useCallback(()=>{if(te.current.length===0)return;const m=te.current.pop();q.current.push(b.map(G=>({...G}))),n||Y(m),t==null||t(m)},[b,n,t]),W=a.useCallback(()=>{if(q.current.length===0)return;const m=q.current.pop();te.current.push(b.map(G=>({...G}))),n||Y(m),t==null||t(m)},[b,n,t]),[le,re]=a.useState(!1),[pe,me]=a.useState(""),[Ne,ne]=a.useState(0),de=a.useMemo(()=>{if(!le||!V)return[];const m=pe.toLowerCase();return _a.filter(G=>G.label.toLowerCase().includes(m)||G.keywords.includes(m))},[le,pe,V]),[ue,ve]=a.useState(null),[se,D]=a.useState(null),T=a.useCallback(m=>{$(b);const G=m(b);n||Y(G),t==null||t(G)},[b,n,t,$]),ae=a.useCallback((m,G)=>{T(Z=>Z.map((fe,Ce)=>Ce===m?{...fe,...G}:fe))},[T]),Q=a.useCallback((m,G)=>{const Z=G??Vt();T(fe=>{const Ce=[...fe];return Ce.splice(m+1,0,Z),Ce}),C(m+1)},[T]),B=a.useCallback(m=>{const G={...b[m],id:jt()};Q(m,G)},[b,Q]),ie=a.useCallback(m=>{b.length<=1||(T(G=>G.filter((Z,fe)=>fe!==m)),C(Math.max(0,m-1)))},[b.length,T]),oe=a.useCallback((m,G)=>{const Z=m+G;Z<0||Z>=b.length||(T(fe=>{const Ce=[...fe];return[Ce[m],Ce[Z]]=[Ce[Z],Ce[m]],Ce}),C(Z))},[b.length,T]),ke=a.useCallback((m,G)=>{const Z={type:G};G==="heading"&&(Z.level=2),G==="list"&&(Z.listType="unordered"),G==="callout"&&(Z.icon="??"),G==="toggle"&&(Z.open=!0),ae(m,Z)},[ae]),ge=a.useCallback(m=>{var Z,fe;const G=ya(m.type);m.type==="list"&&m.label.includes("Numbered")&&(G.listType="ordered"),m.type==="list"&&m.label.includes("Checklist")&&(G.listType="checklist",G.checked=[]),((Z=b[h])==null?void 0:Z.content)===""||((fe=b[h])==null?void 0:fe.content)==="/"?T(Ce=>Ce.map((ze,Fe)=>Fe===h?{...G,id:ze.id}:ze)):Q(h,G),re(!1),me("")},[b,h,T,Q]),ye=a.useCallback((m,G)=>{if(i)return;const Z=b[G];if(!(Z!=null&&Z.locked)){if((m.ctrlKey||m.metaKey)&&m.key==="z"&&!m.shiftKey){m.preventDefault(),P();return}if((m.ctrlKey||m.metaKey)&&(m.key==="y"||m.key==="z"&&m.shiftKey)){m.preventDefault(),W();return}if((m.ctrlKey||m.metaKey)&&m.key==="d"){m.preventDefault(),B(G);return}if((m.ctrlKey||m.metaKey)&&m.key==="b"){m.preventDefault(),ae(G,{bold:!(Z!=null&&Z.bold)});return}if((m.ctrlKey||m.metaKey)&&m.key==="i"){m.preventDefault(),ae(G,{italic:!(Z!=null&&Z.italic)});return}if((m.ctrlKey||m.metaKey)&&m.key==="u"){m.preventDefault(),ae(G,{underline:!(Z!=null&&Z.underline)});return}if((m.ctrlKey||m.metaKey)&&m.key==="e"){m.preventDefault(),ae(G,{strikethrough:!(Z!=null&&Z.strikethrough)});return}if(m.key==="Tab"&&!m.shiftKey){m.preventDefault(),ae(G,{indent:Math.min(((Z==null?void 0:Z.indent)??0)+1,4)});return}if(m.key==="Tab"&&m.shiftKey){m.preventDefault(),ae(G,{indent:Math.max(((Z==null?void 0:Z.indent)??0)-1,0)});return}if((m.ctrlKey||m.metaKey)&&m.key==="f"&&k){m.preventDefault(),x(fe=>!fe);return}if(le&&de.length>0){if(m.key==="ArrowDown"){m.preventDefault(),ne(fe=>Math.min(fe+1,de.length-1));return}if(m.key==="ArrowUp"){m.preventDefault(),ne(fe=>Math.max(fe-1,0));return}if(m.key==="Enter"){m.preventDefault(),ge(de[Ne]);return}if(m.key==="Escape"){re(!1);return}}m.key==="Enter"&&!m.shiftKey?(m.preventDefault(),Q(G)):m.key==="Backspace"&&b[G].content===""&&b.length>1?(m.preventDefault(),ie(G)):m.key==="ArrowUp"&&m.altKey?(m.preventDefault(),oe(G,-1)):m.key==="ArrowDown"&&m.altKey&&(m.preventDefault(),oe(G,1))}},[i,b,Q,ie,oe,P,W,B,ae,le,de,Ne,ge,k]),Me=a.useCallback((m,G)=>{const Z=m.target.textContent??"";V&&Z.startsWith("/")?(re(!0),me(Z.slice(1)),ne(0)):le&&re(!1),$(b);const fe=b.map((Ce,ze)=>ze===G?{...Ce,content:Z}:Ce);n||Y(fe),t==null||t(fe)},[b,n,t,$,V,le]),rt=a.useCallback((m,G)=>{ve(G),m.dataTransfer.effectAllowed="move"},[]),De=a.useCallback((m,G)=>{m.preventDefault(),m.dataTransfer.dropEffect="move",D(G)},[]),He=a.useCallback((m,G)=>{if(m.preventDefault(),ue===null||ue===G){ve(null),D(null);return}T(Z=>{const fe=[...Z],[Ce]=fe.splice(ue,1);return fe.splice(G>ue?G-1:G,0,Ce),fe}),C(G>ue?G-1:G),ve(null),D(null)},[ue,T]);a.useEffect(()=>{if(!L||!p){c([]);return}const m=p.toLowerCase(),G=[];b.forEach((Z,fe)=>{const Ce=(Z.content??"").toLowerCase();let ze=0;for(;ze<Ce.length;){const Fe=Ce.indexOf(m,ze);if(Fe===-1)break;G.push({blockIdx:fe,start:Fe,end:Fe+m.length}),ze=Fe+1}}),c(G),o(0)},[p,L,b]);const lt=a.useCallback(()=>{if(s.length===0)return;const m=(l+1)%s.length;o(m),C(s[m].blockIdx)},[s,l]),st=a.useCallback(()=>{if(s.length===0)return;const m=(l-1+s.length)%s.length;o(m),C(s[m].blockIdx)},[s,l]),ot=a.useCallback(()=>{if(s.length===0||!p)return;const m=s[l],G=b[m.blockIdx],Z=G.content.slice(0,m.start),fe=G.content.slice(m.end);ae(m.blockIdx,{content:Z+y+fe})},[s,l,p,y,b,ae]),ct=a.useCallback(()=>{if(!p)return;const m=p;T(G=>G.map(Z=>({...Z,content:Z.content.split(m).join(y)})))},[p,y,T]),Ke=a.useMemo(()=>g?b.map((m,G)=>m.type==="heading"?{idx:G,level:m.level??2,text:m.content}:null).filter(Boolean):[],[b,g]),dt=a.useCallback(async m=>{var Z;const G=(Z=m.target.files)==null?void 0:Z[0];if(G){if(N){const fe=await N(G);ae(h,{src:fe})}m.target.value=""}},[N,h,ae]);a.useEffect(()=>{const m=b[h];if(m){const G=w.current.get(m.id);G&&G.focus()}},[h,b]);const ut=a.useCallback(()=>{const m=b.map(va).join(`
|
|
416
|
+
`);M==null||M(m)},[b,M]),Le=a.useMemo(()=>H?ka(b):null,[b,H]),[$e,Ee]=a.useState(null),U=a.useCallback((m,G)=>{i||(m.preventDefault(),Ee({x:m.clientX,y:m.clientY,idx:G}))},[i]);return a.useEffect(()=>{if(!$e)return;const m=()=>Ee(null);return window.addEventListener("click",m),()=>window.removeEventListener("click",m)},[$e]),e.jsxs("div",{ref:v,id:I,className:`nice-doc-editor nice-doc-editor--${d} nice-editor--${f} ${i?"nice-doc-editor--readonly":""} ${K??""}`,style:ee,role:"application","aria-label":j("docEditor.label","Document Editor"),...S,children:[r&&!i&&e.jsxs("div",{className:"nice-doc-editor__toolbar",role:"toolbar",style:{display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",padding:"4px 8px"},children:[e.jsx(F.on,{size:"sm",variant:"ghost",onClick:P,title:j("docEditor.undo","Undo (Ctrl+Z)"),children:"?"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:W,title:j("docEditor.redo","Redo (Ctrl+Y)"),children:"?"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(F.Je,{size:"sm",value:((ce=b[h])==null?void 0:ce.type)??"paragraph",onChange:m=>ke(h,m),label:"",options:[{value:"paragraph",label:j("docEditor.paragraph","Paragraph")},{value:"heading",label:j("docEditor.heading","Heading")},{value:"list",label:j("docEditor.list","List")},{value:"code",label:j("docEditor.code","Code")},{value:"quote",label:j("docEditor.quote","Quote")},{value:"callout",label:j("docEditor.callout","Callout")},{value:"toggle",label:j("docEditor.toggle","Toggle")},{value:"divider",label:j("docEditor.divider","Divider")},{value:"image",label:j("docEditor.image","Image")},{value:"video",label:j("docEditor.video","Video")},{value:"pageBreak",label:j("docEditor.pageBreak","Page Break")}],style:{minWidth:100}}),((he=b[h])==null?void 0:he.type)==="heading"&&e.jsx(F.Je,{size:"sm",value:String(((_e=b[h])==null?void 0:_e.level)??2),onChange:m=>ae(h,{level:Number(m)}),label:"",options:[{value:"1",label:"H1"},{value:"2",label:"H2"},{value:"3",label:"H3"},{value:"4",label:"H4"},{value:"5",label:"H5"},{value:"6",label:"H6"}],style:{minWidth:55}}),((be=b[h])==null?void 0:be.type)==="list"&&e.jsx(F.Je,{size:"sm",value:((we=b[h])==null?void 0:we.listType)??"unordered",onChange:m=>ae(h,{listType:m}),label:"",options:[{value:"unordered",label:"� Bullets"},{value:"ordered",label:"1. Numbers"},{value:"checklist",label:"? Checklist"}],style:{minWidth:90}}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(F.on,{size:"sm",variant:(xe=b[h])!=null&&xe.bold?"primary":"ghost",onClick:()=>{var m;return ae(h,{bold:!((m=b[h])!=null&&m.bold)})},title:j("docEditor.bold","Bold (Ctrl+B)"),children:e.jsx("strong",{children:"B"})}),e.jsx(F.on,{size:"sm",variant:(Ie=b[h])!=null&&Ie.italic?"primary":"ghost",onClick:()=>{var m;return ae(h,{italic:!((m=b[h])!=null&&m.italic)})},title:j("docEditor.italic","Italic (Ctrl+I)"),children:e.jsx("em",{children:"I"})}),e.jsx(F.on,{size:"sm",variant:(Te=b[h])!=null&&Te.underline?"primary":"ghost",onClick:()=>{var m;return ae(h,{underline:!((m=b[h])!=null&&m.underline)})},title:j("docEditor.underline","Underline (Ctrl+U)"),children:e.jsx("u",{children:"U"})}),e.jsx(F.on,{size:"sm",variant:(Re=b[h])!=null&&Re.strikethrough?"primary":"ghost",onClick:()=>{var m;return ae(h,{strikethrough:!((m=b[h])!=null&&m.strikethrough)})},title:j("docEditor.strikethrough","Strikethrough (Ctrl+E)"),children:e.jsx("s",{children:"S"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(F.on,{size:"sm",variant:((Ae=b[h])==null?void 0:Ae.align)==="left"?"primary":"ghost",onClick:()=>ae(h,{align:"left"}),title:j("docEditor.alignLeft","Left"),children:"?"}),e.jsx(F.on,{size:"sm",variant:((Qe=b[h])==null?void 0:Qe.align)==="center"?"primary":"ghost",onClick:()=>ae(h,{align:"center"}),title:j("docEditor.alignCenter","Center"),children:"?"}),e.jsx(F.on,{size:"sm",variant:((Oe=b[h])==null?void 0:Oe.align)==="right"?"primary":"ghost",onClick:()=>ae(h,{align:"right"}),title:j("docEditor.alignRight","Right"),children:"?"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>{var m;return ae(h,{indent:Math.min((((m=b[h])==null?void 0:m.indent)??0)+1,4)})},title:j("docEditor.indent","Indent (Tab)"),children:"??"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>{var m;return ae(h,{indent:Math.max((((m=b[h])==null?void 0:m.indent)??0)-1,0)})},title:j("docEditor.outdent","Outdent (Shift+Tab)"),children:"??"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(F.an,{size:"sm",label:"",value:((Ge=b[h])==null?void 0:Ge.color)??"var(--text-primary, #000000)",onChange:m=>ae(h,{color:m}),title:"Text color"}),e.jsx(F.an,{size:"sm",label:"",value:((Ct=b[h])==null?void 0:Ct.bgColor)??"var(--bg-primary, #ffffff)",onChange:m=>ae(h,{bgColor:m}),title:"Block background"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(F.on,{size:"sm",variant:(Nt=b[h])!=null&&Nt.locked?"primary":"ghost",onClick:()=>{var m;return ae(h,{locked:!((m=b[h])!=null&&m.locked)})},title:j("docEditor.lock","Lock/Unlock block"),children:"??"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>B(h),title:j("docEditor.duplicate","Duplicate (Ctrl+D)"),children:"?"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>ie(h),title:j("docEditor.delete","Delete block"),children:"??"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>Q(h),title:j("docEditor.addBlock","Add block"),children:"+"}),k&&e.jsx(F.on,{size:"sm",variant:L?"primary":"ghost",onClick:()=>x(m=>!m),title:j("docEditor.find","Find & Replace (Ctrl+F)"),children:"??"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>J(m=>!m),title:j("docEditor.shortcuts","Keyboard shortcuts"),children:"?"}),M&&e.jsx(F.on,{size:"sm",variant:"ghost",onClick:ut,children:j("docEditor.export","Export HTML")})]}),e.jsx("input",{ref:O,type:"file",accept:"image/*,video/*",style:{display:"none"},onChange:dt}),L&&e.jsxs("div",{className:"nice-doc-editor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--nice-doc-find-bg, #f8f9fa)",borderBottom:"1px solid var(--border-color, #ddd)"},children:[e.jsx(F.Ye,{size:"sm",placeholder:j("docEditor.findPlaceholder","Find..."),value:p,onChange:R,style:{flex:1,maxWidth:200}}),e.jsx(F.Ye,{size:"sm",placeholder:j("docEditor.replacePlaceholder","Replace..."),value:y,onChange:u,style:{flex:1,maxWidth:200}}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:st,title:j("docEditor.findPrev","Previous"),children:"?"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:lt,title:j("docEditor.findNext","Next"),children:"?"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:ot,title:j("docEditor.replaceOne","Replace"),disabled:i,children:j("docEditor.replace","Replace")}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:ct,title:j("docEditor.replaceAll","Replace all"),disabled:i,children:j("docEditor.replaceAllBtn","All")}),e.jsx("span",{style:{fontSize:"0.75em",color:"var(--text-muted, #666)"},children:s.length>0?`${l+1}/${s.length}`:"0/0"}),e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>x(!1),children:"?"})]}),E&&e.jsx("div",{className:"nice-doc-editor__shortcuts-overlay",style:{position:"fixed",inset:0,background:"rgba(0,0,0,.4)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>J(!1),children:e.jsxs("div",{style:{background:"var(--bg-primary, #fff)",borderRadius:8,padding:24,maxWidth:420,width:"90%",boxShadow:"0 8px 32px rgba(0,0,0,.2)"},onClick:m=>m.stopPropagation(),children:[e.jsx("h3",{style:{margin:"0 0 12px"},children:j("docEditor.shortcutsTitle","Keyboard Shortcuts")}),e.jsx("table",{style:{width:"100%",fontSize:"0.875em",borderCollapse:"collapse"},children:e.jsx("tbody",{children:[["Ctrl+B",j("docEditor.bold","Bold")],["Ctrl+I",j("docEditor.italic","Italic")],["Ctrl+U",j("docEditor.underline","Underline")],["Ctrl+E",j("docEditor.strikethrough","Strikethrough")],["Ctrl+D",j("docEditor.duplicate","Duplicate block")],["Ctrl+Z",j("docEditor.undo","Undo")],["Ctrl+Y",j("docEditor.redo","Redo")],["Ctrl+F",j("docEditor.find","Find & Replace")],["Enter",j("docEditor.newBlock","New block")],["Backspace",j("docEditor.deleteEmpty","Delete empty block")],["Alt+?",j("docEditor.moveUp","Move block up")],["Alt+?",j("docEditor.moveDown","Move block down")],["Tab",j("docEditor.indent","Indent")],["Shift+Tab",j("docEditor.outdent","Outdent")],["/",j("docEditor.slashCmd","Slash commands")]].map(([m,G])=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-color, #eee)"},children:[e.jsx("td",{style:{padding:"4px 8px",fontFamily:"monospace",fontWeight:600},children:m}),e.jsx("td",{style:{padding:"4px 8px"},children:G})]},m))})}),e.jsx("div",{style:{textAlign:"right",marginTop:12},children:e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>J(!1),children:j("docEditor.close","Close")})})]})}),e.jsxs("div",{style:{display:"flex",gap:0},children:[g&&Ke.length>0&&e.jsxs("nav",{className:"nice-doc-editor__toc",style:{width:200,minWidth:160,borderRight:"1px solid var(--border-color, #eee)",padding:"8px 4px",fontSize:"0.8em",overflowY:"auto",maxHeight:500},children:[e.jsx("div",{style:{fontWeight:600,padding:"4px 8px",fontSize:"0.75em",textTransform:"uppercase",color:"var(--text-muted, #999)"},children:j("docEditor.toc","Contents")}),Ke.map(m=>e.jsx("div",{style:{padding:"3px 8px",paddingLeft:8+(m.level-1)*12,cursor:"pointer",borderRadius:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",background:m.idx===h?"#e8f0fe":void 0},onClick:()=>C(m.idx),title:m.text,children:m.text||j("docEditor.untitled","Untitled")},m.idx))]}),e.jsx("div",{className:"nice-doc-editor__body",style:{flex:1},children:b.map((m,G)=>e.jsxs("div",{className:`nice-doc-editor__block nice-doc-editor__block--${m.type} ${G===h?"nice-doc-editor__block--focused":""} ${se===G?"nice-doc-editor__block--drop-target":""} ${m.locked?"nice-doc-editor__block--locked":""}`,onClick:()=>C(G),onContextMenu:Z=>U(Z,G),draggable:!i&&!m.locked,onDragStart:Z=>rt(Z,G),onDragOver:Z=>De(Z,G),onDrop:Z=>He(Z,G),onDragEnd:()=>{ve(null),D(null)},style:{opacity:ue===G?.4:1,marginLeft:(m.indent??0)*24},children:[!i&&!m.locked&&e.jsx("div",{className:"nice-doc-editor__block-handle",title:j("docEditor.drag","Drag to reorder"),children:"?"}),m.locked&&e.jsx("span",{className:"nice-doc-editor__lock-icon",style:{position:"absolute",top:2,right:4,fontSize:"0.7em",opacity:.5},children:"??"}),m.type==="divider"?e.jsx("hr",{className:"nice-doc-editor__divider"}):m.type==="pageBreak"?e.jsxs("div",{className:"nice-doc-editor__page-break",style:{borderTop:"2px dashed #ccc",textAlign:"center",padding:4,fontSize:"0.75em",color:"var(--text-muted, #999)"},children:["� ",j("docEditor.pageBreak","Page Break")," �"]}):m.type==="image"||m.type==="video"?e.jsx("div",{className:"nice-doc-editor__media-block",children:m.src?m.type==="image"?e.jsx("img",{src:m.src,alt:m.alt??"",className:"nice-doc-editor__image",style:{maxWidth:"100%"}}):e.jsx("video",{src:m.src,controls:!0,className:"nice-doc-editor__video",style:{maxWidth:"100%"}}):!i&&e.jsxs("div",{style:{display:"flex",gap:4,alignItems:"center"},children:[e.jsx(F.Ye,{size:"sm",placeholder:j("docEditor.mediaUrl",m.type==="image"?"Image URL":"Video URL"),value:m.src??"",onChange:Z=>ae(G,{src:Z})}),N&&e.jsx(F.on,{size:"sm",variant:"ghost",onClick:()=>{var Z;C(G),(Z=O.current)==null||Z.click()},children:"??"})]})}):m.type==="callout"?e.jsxs("div",{className:"nice-doc-editor__callout",style:{display:"flex",gap:8,padding:"8px 12px",background:m.bgColor??"#f0f7ff",borderRadius:4,color:m.color},children:[e.jsx("span",{style:{fontSize:"1.2em"},children:m.icon??"??"}),e.jsx("div",{ref:Z=>{Z&&w.current.set(m.id,Z)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,onInput:Z=>Me(Z,G),onFocus:()=>C(G),onKeyDown:Z=>ye(Z,G),"data-placeholder":j("docEditor.calloutPlaceholder","Callout text..."),role:"textbox","aria-multiline":"true",style:{flex:1,outline:"none"},children:m.content})]}):m.type==="toggle"?e.jsxs("details",{open:m.open,className:"nice-doc-editor__toggle",onToggle:Z=>ae(G,{open:Z.target.open}),children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:500},children:m.content.split(`
|
|
417
|
+
`)[0]||j("docEditor.toggleTitle","Toggle")}),e.jsx("div",{ref:Z=>{Z&&w.current.set(m.id,Z)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,onInput:Z=>Me(Z,G),onFocus:()=>C(G),onKeyDown:Z=>ye(Z,G),role:"textbox","aria-multiline":"true",style:{padding:"4px 0"},children:m.content.split(`
|
|
418
|
+
`).slice(1).join(`
|
|
419
|
+
`)})]}):m.type==="code"?e.jsxs("div",{className:"nice-doc-editor__code-block",style:{position:"relative"},children:[!i&&e.jsx(F.Ye,{size:"sm",value:m.language??"",onChange:Z=>ae(G,{language:Z}),placeholder:"Language",style:{position:"absolute",top:4,right:4,width:80,opacity:.7}}),e.jsx("pre",{ref:Z=>{Z&&w.current.set(m.id,Z)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,onInput:Z=>Me(Z,G),onFocus:()=>C(G),onKeyDown:Z=>ye(Z,G),role:"textbox","aria-multiline":"true",style:{fontFamily:"monospace",background:"var(--bg-elevated, #1e1e1e)",color:"var(--text-secondary, #d4d4d4)",padding:12,borderRadius:4,overflow:"auto"},children:m.content})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:Z=>{Z&&w.current.set(m.id,Z)},className:"nice-doc-editor__content",contentEditable:!i&&!m.locked,suppressContentEditableWarning:!0,style:{textAlign:m.align,fontWeight:m.bold?"bold":void 0,fontStyle:m.italic?"italic":void 0,textDecoration:[m.underline?"underline":"",m.strikethrough?"line-through":""].filter(Boolean).join(" ")||void 0,color:m.color,backgroundColor:m.bgColor},onInput:Z=>Me(Z,G),onFocus:()=>C(G),onKeyDown:Z=>ye(Z,G),"data-placeholder":!m.content&&_?_:void 0,role:"textbox","aria-multiline":"true",children:m.content}),le&&G===h&&de.length>0&&e.jsx("ul",{className:"nice-doc-editor__slash-menu",style:{position:"absolute",left:0,top:"100%",zIndex:100,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,.12)",listStyle:"none",margin:0,padding:4,minWidth:180,maxHeight:240,overflow:"auto"},children:de.map((Z,fe)=>e.jsxs("li",{className:fe===Ne?"nice-doc-editor__slash-item--active":"",style:{padding:"6px 10px",cursor:"pointer",borderRadius:4,display:"flex",gap:8,alignItems:"center",background:fe===Ne?"#e8f0fe":void 0},onMouseDown:Ce=>{Ce.preventDefault(),ge(Z)},onMouseEnter:()=>ne(fe),children:[e.jsx("span",{style:{width:24,textAlign:"center"},children:Z.icon}),e.jsx("span",{children:Z.label})]},`${Z.type}-${Z.label}`))})]})]},m.id))})]}),$e&&e.jsxs("div",{className:"nice-doc-editor__ctx-menu",style:{position:"fixed",left:$e.x,top:$e.y,zIndex:1e3,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px rgba(0,0,0,.12)",padding:4,minWidth:160},children:[e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{B($e.idx),Ee(null)},children:"? Duplicate"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{Q($e.idx),Ee(null)},children:"+ Insert below"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{oe($e.idx,-1),Ee(null)},children:"? Move up"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{oe($e.idx,1),Ee(null)},children:"? Move down"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{var m;ae($e.idx,{locked:!((m=b[$e.idx])!=null&&m.locked)}),Ee(null)},children:(wt=b[$e.idx])!=null&&wt.locked?"?? Unlock":"?? Lock"}),e.jsx("hr",{style:{margin:"2px 0",border:"none",borderTop:"1px solid var(--border-color, #eee)"}}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer",color:"#d32f2f"},onClick:()=>{ie($e.idx),Ee(null)},children:"?? Delete"})]}),H&&Le&&e.jsxs("div",{className:"nice-doc-editor__footer",style:{padding:"4px 12px",fontSize:"0.75em",color:"var(--text-muted, #666)",borderTop:"1px solid var(--border-color, #eee)",display:"flex",gap:16},children:[e.jsxs("span",{children:[Le.words," ",j("docEditor.words","words")]}),e.jsxs("span",{children:[Le.chars," ",j("docEditor.chars","characters")]}),e.jsxs("span",{children:[b.length," ",j("docEditor.blocks","blocks")]}),e.jsxs("span",{children:["~",Le.readingTime," ",j("docEditor.readingTime","min read")]})]})]})});xn.displayName="NiceDocumentEditor";const ja=["street","streetNumber","apartment","city","postalCode","state","country"],et={street:"Street",streetNumber:"Number",apartment:"Apt/Suite",city:"City",postalCode:"Postal Code",state:"State/Province",country:"Country"},yn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g={},onChange:k,fields:K=ja,placeholders:ee={},countries:X,layout:S="vertical",countryFirst:v=!1,validatePostalCode:I},j)=>{const A=F.rl(H,N);if(A==="hidden")return null;A==="disabled"&&(d=!0),A==="readOnly"&&(f=!0);const{t:Y}=F.ue(),b=F.Os(N),h=a.useCallback((L,x)=>{k==null||k({...g,[L]:x})},[g,k]),C=a.useMemo(()=>{if(I&&g.postalCode)return I(g.postalCode,g.country)},[I,g.postalCode,g.country]),w=a.useMemo(()=>v&&K.includes("country")?["country",...K.filter(L=>L!=="country")]:K,[K,v]),O=`nice-address nice-address--${S} nice-size-${_}`;return e.jsxs("div",{ref:j,id:b,className:`${O}${z?` ${z}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:V,role:"group","aria-label":n??Y("address","Address"),children:[n&&e.jsxs("label",{className:"nice-address__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-address__fields",children:w.map(L=>L==="country"&&X?e.jsxs("div",{className:`nice-address__field nice-address__field--${L}`,children:[e.jsx("label",{className:"nice-address__field-label",children:Y(L,et[L])}),e.jsxs("select",{className:"nice-input nice-select",value:g.country??"",onChange:x=>h("country",x.target.value),disabled:d,"aria-label":Y(L,et[L]),children:[e.jsx("option",{value:"",children:ee.country??Y("selectCountry","— Select country —")}),X.map(x=>e.jsx("option",{value:x.code,children:x.name},x.code))]})]},L):e.jsxs("div",{className:`nice-address__field nice-address__field--${L}`,children:[e.jsx("label",{className:"nice-address__field-label",children:Y(L,et[L])}),e.jsx("input",{className:`nice-input${L==="postalCode"&&C?" nice-input--error":""}`,type:"text",name:M?`${M}.${L}`:L,value:g[L]??"",onChange:x=>h(L,x.target.value),placeholder:ee[L]??"",disabled:d,readOnly:f,"aria-label":Y(L,et[L])}),L==="postalCode"&&C&&e.jsx("span",{className:"nice-error-text",children:C})]},L))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});yn.displayName="NiceAddressInput";const Ca=[{code:"PLN",symbol:"zł",name:"Polish Zloty"},{code:"EUR",symbol:"€",name:"Euro"},{code:"USD",symbol:"$",name:"US Dollar"},{code:"GBP",symbol:"£",name:"British Pound"},{code:"CZK",symbol:"Kč",name:"Czech Koruna"},{code:"CHF",symbol:"Fr",name:"Swiss Franc"}],_n=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g,onChange:k,onBlur:K,currency:ee="PLN",onCurrencyChange:X,currencies:S=Ca,useMinorUnit:v=!1,min:I,max:j,locale:A,placeholder:Y,showCurrencySelector:b},h)=>{const C=F.rl(H,N);if(C==="hidden")return null;C==="disabled"&&(d=!0),C==="readOnly"&&(f=!0);const{t:w}=F.ue(),O=F.Os(N),L=a.useMemo(()=>S.find(s=>s.code===ee)??S[0],[ee,S]),x=(L==null?void 0:L.decimals)??2,p=a.useMemo(()=>g==null?"":(v?g/Math.pow(10,x):g).toFixed(x),[g,v,x]),R=a.useCallback(s=>{const c=s.replace(/[^\d.,\-]/g,"").replace(",",".");if(c===""||c==="-"){k==null||k(null);return}const l=parseFloat(c);if(isNaN(l))return;const o=v?Math.round(l*Math.pow(10,x)):l;I!=null&&o<I||j!=null&&o>j||(k==null||k(o))},[k,v,x,I,j]),y=b??S.length>1,u=a.useMemo(()=>{if(g==null)return"";const s=v?g/Math.pow(10,x):g;try{return new Intl.NumberFormat(A,{style:"currency",currency:(L==null?void 0:L.code)??"USD",minimumFractionDigits:x}).format(s)}catch{return`${s.toFixed(x)} ${L==null?void 0:L.code}`}},[g,v,x,A,L]);return e.jsxs("div",{ref:h,id:O,className:`nice-currency nice-size-${_}${z?` ${z}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:V,children:[n&&e.jsxs("label",{className:"nice-currency__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-currency__row",children:[y&&e.jsx("select",{className:"nice-currency__select nice-select",value:ee,onChange:s=>X==null?void 0:X(s.target.value),disabled:d,"aria-label":w("currency","Currency"),children:S.map(s=>e.jsxs("option",{value:s.code,children:[s.symbol," ",s.code]},s.code))}),!y&&e.jsx("span",{className:"nice-currency__symbol",children:L==null?void 0:L.symbol}),e.jsx("input",{className:"nice-input nice-currency__amount",type:"text",inputMode:"decimal",name:M,value:p,onChange:s=>R(s.target.value),onBlur:K,placeholder:Y??`0.${"0".repeat(x)}`,disabled:d,readOnly:f,"aria-label":w("amount","Amount")})]}),u&&g!=null&&e.jsx("span",{className:"nice-currency__formatted",children:u}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});_n.displayName="NiceCurrencyInput";let Na=1;function wa(n){return{id:`new-${Na++}`,description:"",quantity:1,unitPrice:0,vatRate:n,discount:0,unit:"szt."}}function vn(n){const t=n.quantity*n.unitPrice*(1-(n.discount??0)/100),i=Math.round(t*100)/100,r=Math.round(i*(n.vatRate??0)/100*100)/100;return{...n,netAmount:i,grossAmount:i+r}}function $a(n){const t=n.map(vn),i=t.reduce((M,N)=>M+(N.netAmount??0),0),r=t.reduce((M,N)=>M+(N.grossAmount??0),0),d=r-i,f=new Map;for(const M of t){const N=M.vatRate??0,z=f.get(N)??{base:0,amount:0};z.base+=M.netAmount??0,z.amount+=(M.grossAmount??0)-(M.netAmount??0),f.set(N,z)}const _=Array.from(f.entries()).map(([M,N])=>({rate:M,base:Math.round(N.base*100)/100,amount:Math.round(N.amount*100)/100}));return{totalNet:Math.round(i*100)/100,totalVat:Math.round(d*100)/100,totalGross:Math.round(r*100)/100,vatBreakdown:_}}const kn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g=[],onChange:k,onTotalsChange:K,currencySymbol:ee="zł",defaultVatRate:X=23,vatRates:S=[0,5,8,23],units:v=["szt.","h","kg","m","usł."],showDiscount:I=!0,showUnit:j=!0,showTotals:A=!0,editable:Y=!0,maxLines:b},h)=>{const C=F.rl(H,N);if(C==="hidden")return null;C==="disabled"&&(d=!0),C==="readOnly"&&(f=!0);const{t:w}=F.ue(),O=F.Os(N),L=a.useMemo(()=>g.map(vn),[g]),x=a.useMemo(()=>$a(g),[g]);a.useEffect(()=>{K==null||K(x)},[x,K]);const p=a.useCallback((s,c,l)=>{const o=[...g];o[s]={...o[s],[c]:l},k==null||k(o)},[g,k]),R=a.useCallback(()=>{b&&g.length>=b||(k==null||k([...g,wa(X)]))},[g,k,X,b]),y=a.useCallback(s=>{k==null||k(g.filter((c,l)=>l!==s))},[g,k]),u=s=>`${s.toFixed(2)} ${ee}`;return e.jsxs("div",{ref:h,id:O,className:`nice-invoice-lines nice-size-${_}${z?` ${z}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:V,children:[n&&e.jsxs("label",{className:"nice-invoice-lines__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("table",{className:"nice-invoice-lines__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-il__th-num",children:"#"}),e.jsx("th",{className:"nice-il__th-desc",children:w("description","Description")}),e.jsx("th",{className:"nice-il__th-qty",children:w("qty","Qty")}),j&&e.jsx("th",{className:"nice-il__th-unit",children:w("unit","Unit")}),e.jsx("th",{className:"nice-il__th-price",children:w("unitPrice","Unit Price")}),I&&e.jsx("th",{className:"nice-il__th-disc",children:w("discount","Disc %")}),e.jsx("th",{className:"nice-il__th-vat",children:w("vat","VAT %")}),e.jsx("th",{className:"nice-il__th-net",children:w("net","Net")}),e.jsx("th",{className:"nice-il__th-gross",children:w("gross","Gross")}),Y&&!f&&e.jsx("th",{className:"nice-il__th-actions"})]})}),e.jsx("tbody",{children:L.map((s,c)=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-il__cell-num",children:c+1}),e.jsx("td",{className:"nice-il__cell-desc",children:e.jsx("input",{className:"nice-input",type:"text",value:s.description,onChange:l=>p(c,"description",l.target.value),disabled:d,readOnly:f,placeholder:w("itemDescription","Item description")})}),e.jsx("td",{className:"nice-il__cell-qty",children:e.jsx("input",{className:"nice-input",type:"number",value:s.quantity,onChange:l=>p(c,"quantity",parseFloat(l.target.value)||0),disabled:d,readOnly:f,min:0,step:"any"})}),j&&e.jsx("td",{className:"nice-il__cell-unit",children:e.jsx("select",{className:"nice-select",value:s.unit??"",onChange:l=>p(c,"unit",l.target.value),disabled:d,children:v.map(l=>e.jsx("option",{value:l,children:l},l))})}),e.jsx("td",{className:"nice-il__cell-price",children:e.jsx("input",{className:"nice-input",type:"number",value:s.unitPrice,onChange:l=>p(c,"unitPrice",parseFloat(l.target.value)||0),disabled:d,readOnly:f,min:0,step:"0.01"})}),I&&e.jsx("td",{className:"nice-il__cell-disc",children:e.jsx("input",{className:"nice-input",type:"number",value:s.discount??0,onChange:l=>p(c,"discount",parseFloat(l.target.value)||0),disabled:d,readOnly:f,min:0,max:100})}),e.jsx("td",{className:"nice-il__cell-vat",children:e.jsx("select",{className:"nice-select",value:s.vatRate??0,onChange:l=>p(c,"vatRate",parseInt(l.target.value,10)),disabled:d,children:S.map(l=>e.jsxs("option",{value:l,children:[l,"%"]},l))})}),e.jsx("td",{className:"nice-il__cell-net",children:u(s.netAmount??0)}),e.jsx("td",{className:"nice-il__cell-gross",children:u(s.grossAmount??0)}),Y&&!f&&e.jsx("td",{className:"nice-il__cell-actions",children:e.jsx("button",{type:"button",className:"nice-btn nice-btn--icon nice-btn--sm",onClick:()=>y(c),disabled:d,title:w("remove","Remove"),children:"✕"})})]},s.id))})]}),Y&&!f&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outlined nice-btn--sm nice-invoice-lines__add",onClick:R,disabled:d||b!=null&&g.length>=b,children:["+ ",w("addLine","Add line")]}),A&&e.jsxs("div",{className:"nice-invoice-lines__totals",children:[e.jsxs("div",{className:"nice-il__total-row",children:[e.jsxs("span",{children:[w("totalNet","Net total"),":"]}),e.jsx("span",{className:"nice-il__total-value",children:u(x.totalNet)})]}),x.vatBreakdown.map(s=>e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--vat",children:[e.jsxs("span",{children:["VAT ",s.rate,"%:"]}),e.jsx("span",{className:"nice-il__total-value",children:u(s.amount)})]},s.rate)),e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--gross",children:[e.jsxs("span",{children:[w("totalGross","Gross total"),":"]}),e.jsx("span",{className:"nice-il__total-value nice-il__total-value--gross",children:u(x.totalGross)})]})]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});kn.displayName="NiceInvoiceLineEditor";const jn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g=[],onChange:k,contacts:K=[],onSearch:ee,searchDelay:X=300,multiple:S=!1,placeholder:v,onContactClick:I,maxSelections:j},A)=>{const Y=F.rl(H,N);if(Y==="hidden")return null;Y==="disabled"&&(d=!0),Y==="readOnly"&&(f=!0);const{t:b}=F.ue(),h=F.Os(N),[C,w]=a.useState(""),[O,L]=a.useState([]),[x,p]=a.useState(!1),[R,y]=a.useState(!1),u=a.useMemo(()=>{const o=[...K,...O],E=new Map(o.map(J=>[J.id,J]));return g.map(J=>E.get(J)).filter(Boolean)},[g,K,O]),s=a.useCallback(o=>{if(w(o),o.length<1){L([]),p(!1);return}if(ee){y(!0);const te=setTimeout(async()=>{const q=await ee(o);L(q),p(!0),y(!1)},X);return()=>clearTimeout(te)}const E=o.toLowerCase(),J=K.filter(te=>{var q,$;return te.name.toLowerCase().includes(E)||((q=te.email)==null?void 0:q.toLowerCase().includes(E))||(($=te.phone)==null?void 0:$.includes(o))});L(J),p(!0)},[ee,K,X]),c=a.useCallback(o=>{if(S)if(g.includes(o.id))k==null||k(g.filter(E=>E!==o.id));else{if(j&&g.length>=j)return;k==null||k([...g,o.id])}else k==null||k([o.id]),p(!1),w("")},[g,k,S,j]),l=a.useCallback(o=>{k==null||k(g.filter(E=>E!==o))},[g,k]);return e.jsxs("div",{ref:A,id:h,className:`nice-contact-picker nice-size-${_}${z?` ${z}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:V,children:[n&&e.jsxs("label",{className:"nice-contact-picker__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),u.length>0&&e.jsx("div",{className:"nice-contact-picker__chips",children:u.map(o=>e.jsxs("span",{className:"nice-contact-picker__chip",onClick:()=>I==null?void 0:I(o),children:[o.avatarUrl&&e.jsx("img",{src:o.avatarUrl,alt:"",className:"nice-contact-picker__chip-avatar"}),e.jsx("span",{children:o.name}),!f&&e.jsx("button",{type:"button",className:"nice-contact-picker__chip-remove",onClick:E=>{E.stopPropagation(),l(o.id)},disabled:d,children:"×"})]},o.id))}),!f&&e.jsxs("div",{className:"nice-contact-picker__search",children:[e.jsx("input",{className:"nice-input",type:"text",value:C,onChange:o=>s(o.target.value),onFocus:()=>C.length>0&&p(!0),onBlur:()=>setTimeout(()=>p(!1),200),placeholder:v??b("searchContacts","Search contacts…"),disabled:d,"aria-label":b("searchContacts","Search contacts")}),R&&e.jsx("span",{className:"nice-contact-picker__spinner",children:"⏳"})]}),x&&O.length>0&&e.jsx("div",{className:"nice-contact-picker__dropdown",role:"listbox",children:O.map(o=>e.jsxs("div",{className:`nice-contact-picker__option${g.includes(o.id)?" nice-contact-picker__option--selected":""}`,role:"option","aria-selected":g.includes(o.id),onClick:()=>c(o),children:[o.avatarUrl&&e.jsx("img",{src:o.avatarUrl,alt:"",className:"nice-contact-picker__option-avatar"}),e.jsxs("div",{className:"nice-contact-picker__option-info",children:[e.jsx("span",{className:"nice-contact-picker__option-name",children:o.name}),o.subtitle&&e.jsx("span",{className:"nice-contact-picker__option-subtitle",children:o.subtitle}),o.email&&e.jsx("span",{className:"nice-contact-picker__option-email",children:o.email})]}),o.type&&e.jsx("span",{className:"nice-contact-picker__option-type",children:o.type==="person"?"👤":"🏢"})]},o.id))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});jn.displayName="NiceContactPicker";const Ma=["highlight","underline","strikethrough","freehand","text","rect","arrow"],Sa={highlight:"🖍️",underline:"⎁",strikethrough:"S̶",freehand:"✏️",text:"T",rect:"▭",arrow:"→",stamp:"🔏"},Cn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",id:M,className:N,style:z,accessMode:V,src:H,annotations:g=[],onAnnotationsChange:k,activeTool:K,onToolChange:ee,currentPage:X=1,onPageChange:S,totalPages:v=1,defaultColor:I="#FFFF00",tools:j=Ma,author:A,zoom:Y=1,onZoomChange:b,onAnnotationClick:h,onAnnotationDelete:C},w)=>{const O=F.rl(V,M);if(O==="hidden")return null;O==="disabled"&&(d=!0),O==="readOnly"&&(f=!0);const{t:L}=F.ue(),x=F.Os(M),p=g.filter(u=>u.page===X),R=a.useCallback(u=>{ee==null||ee(K===u?null:u)},[K,ee]),y=a.useCallback(u=>{if(f||!K||K==="freehand")return;const s=u.currentTarget.getBoundingClientRect(),c=(u.clientX-s.left)/s.width,l=(u.clientY-s.top)/s.height,o={id:`ann-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,tool:K,page:X,x:c,y:l,color:I,author:A,createdAt:new Date().toISOString(),text:K==="text"?"":void 0};k==null||k([...g,o])},[f,K,X,I,A,g,k]);return e.jsxs("div",{ref:w,id:x,className:`nice-pdf-annotation nice-size-${_}${N?` ${N}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:z,children:[n&&e.jsxs("div",{className:"nice-pdf-annotation__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),!f&&e.jsxs("div",{className:"nice-pdf-annotation__toolbar",children:[j.map(u=>e.jsx("button",{type:"button",className:`nice-pdf-annotation__tool-btn${K===u?" nice-pdf-annotation__tool-btn--active":""}`,onClick:()=>R(u),disabled:d,title:L(`pdfTool_${u}`,u),children:Sa[u]},u)),e.jsx("span",{className:"nice-pdf-annotation__toolbar-sep"}),e.jsx("button",{type:"button",disabled:d,onClick:()=>b==null?void 0:b(Math.max(.25,Y-.25)),title:L("zoomOut","Zoom out"),children:"−"}),e.jsxs("span",{className:"nice-pdf-annotation__zoom",children:[Math.round(Y*100),"%"]}),e.jsx("button",{type:"button",disabled:d,onClick:()=>b==null?void 0:b(Math.min(4,Y+.25)),title:L("zoomIn","Zoom in"),children:"+"})]}),e.jsxs("div",{className:"nice-pdf-annotation__viewport",style:{transform:`scale(${Y})`,transformOrigin:"top left"},children:[e.jsx("iframe",{src:H,className:"nice-pdf-annotation__frame",title:L("pdfViewer","PDF Viewer")}),e.jsx("div",{className:"nice-pdf-annotation__layer",onClick:y,children:p.map(u=>e.jsxs("div",{className:`nice-pdf-annotation__mark nice-pdf-annotation__mark--${u.tool}`,style:{left:`${u.x*100}%`,top:`${u.y*100}%`,backgroundColor:u.color},onClick:s=>{s.stopPropagation(),h==null||h(u)},title:u.text??u.tool,children:[u.text&&e.jsx("span",{children:u.text}),!f&&e.jsx("button",{type:"button",className:"nice-pdf-annotation__mark-delete",onClick:s=>{s.stopPropagation(),C==null||C(u.id)},children:"×"})]},u.id))})]}),e.jsxs("div",{className:"nice-pdf-annotation__pager",children:[e.jsx("button",{type:"button",disabled:d||X<=1,onClick:()=>S==null?void 0:S(X-1),children:"◀"}),e.jsx("span",{children:L("pageOf","{page} / {total}").replace("{page}",String(X)).replace("{total}",String(v))}),e.jsx("button",{type:"button",disabled:d||X>=v,onClick:()=>S==null?void 0:S(X+1),children:"▶"})]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Cn.displayName="NicePDFAnnotationEditor";const Nn=a.forwardRef(({label:n,helperText:t,error:i,disabled:r,readOnly:d,size:f="md",id:_,className:M,style:N,accessMode:z,pages:V,selectedPageId:H,content:g="",contentFormat:k="html",editing:K=!1,onPageSelect:ee,onContentChange:X,onSave:S,onCreatePage:v,onDeletePage:I,onEditToggle:j,onVersionHistory:A,sidebarWidth:Y=260,sidebarCollapsed:b=!1,onSidebarToggle:h,searchable:C=!0,onSearch:w},O)=>{const L=F.rl(z,_);if(L==="hidden")return null;L==="disabled"&&(r=!0),L==="readOnly"&&(d=!0);const{t:x}=F.ue(),p=F.Os(_),[R,y]=a.useState(""),[u,s]=a.useState(""),[c,l]=a.useState(!1),o=a.useMemo(()=>{const q=$=>{for(const P of $){if(P.id===H)return P;if(P.children){const W=q(P.children);if(W)return W}}};return q(V)},[V,H]),E=a.useCallback(q=>{y(q),w==null||w(q)},[w]),J=a.useCallback(()=>{u.trim()&&(v==null||v(H??null,u.trim()),s(""),l(!1))},[u,H,v]),te=(q,$=0)=>e.jsx("ul",{className:"nice-wiki__tree",style:{paddingLeft:$>0?16:0},children:q.map(P=>{var W;return e.jsxs("li",{className:"nice-wiki__tree-item",children:[e.jsxs("div",{className:`nice-wiki__tree-node${P.id===H?" nice-wiki__tree-node--active":""}${P.isDraft?" nice-wiki__tree-node--draft":""}`,onClick:()=>ee==null?void 0:ee(P),role:"treeitem","aria-selected":P.id===H,children:[e.jsx("span",{className:"nice-wiki__tree-icon",children:(W=P.children)!=null&&W.length?"📁":"📄"}),e.jsx("span",{className:"nice-wiki__tree-title",children:P.title}),P.isDraft&&e.jsx("span",{className:"nice-wiki__tree-draft",children:x("draft","Draft")})]}),P.children&&P.children.length>0&&te(P.children,$+1)]},P.id)})});return e.jsxs("div",{ref:O,id:p,className:`nice-wiki nice-size-${f}${M?` ${M}`:""}${r?" nice-disabled":""}`,style:N,children:[!b&&e.jsxs("aside",{className:"nice-wiki__sidebar",style:{width:Y},children:[e.jsxs("div",{className:"nice-wiki__sidebar-header",children:[e.jsx("span",{className:"nice-wiki__sidebar-title",children:n??x("wiki","Wiki")}),h&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-toggle",onClick:()=>h(!0),children:"«"})]}),C&&e.jsx("input",{type:"text",className:"nice-input nice-wiki__search",value:R,onChange:q=>E(q.target.value),placeholder:x("searchPages","Search pages…"),disabled:r}),e.jsx("div",{className:"nice-wiki__page-tree",role:"tree",children:te(V)}),v&&!d&&e.jsx("div",{className:"nice-wiki__sidebar-footer",children:c?e.jsxs("div",{className:"nice-wiki__create-form",children:[e.jsx("input",{type:"text",className:"nice-input",value:u,onChange:q=>s(q.target.value),placeholder:x("pageTitle","Page title"),onKeyDown:q=>q.key==="Enter"&&J(),disabled:r}),e.jsx("button",{type:"button",disabled:r||!u.trim(),onClick:J,children:"✓"}),e.jsx("button",{type:"button",onClick:()=>l(!1),children:"✕"})]}):e.jsxs("button",{type:"button",className:"nice-wiki__add-page",onClick:()=>l(!0),disabled:r,children:["+ ",x("newPage","New page")]})})]}),b&&h&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-expand",onClick:()=>h(!1),children:"»"}),e.jsx("main",{className:"nice-wiki__content",children:o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-wiki__content-header",children:[e.jsx("h1",{className:"nice-wiki__page-title",children:o.title}),e.jsxs("div",{className:"nice-wiki__content-actions",children:[j&&!d&&e.jsx("button",{type:"button",disabled:r,onClick:()=>j(!K),children:K?x("preview","Preview"):x("edit","Edit")}),A&&e.jsx("button",{type:"button",disabled:r,onClick:()=>A(o.id),children:x("history","History")}),I&&!d&&e.jsx("button",{type:"button",className:"nice-btn--danger",disabled:r,onClick:()=>I(o.id),children:x("delete","Delete")})]})]}),o.updatedAt&&e.jsxs("div",{className:"nice-wiki__page-meta",children:[o.updatedBy&&e.jsxs("span",{children:[x("lastEditedBy","Last edited by")," ",o.updatedBy]}),e.jsx("span",{children:new Date(o.updatedAt).toLocaleDateString()})]}),K?e.jsxs("div",{className:"nice-wiki__editor",children:[e.jsx("textarea",{className:"nice-wiki__editor-textarea",value:g,onChange:q=>X==null?void 0:X(q.target.value),disabled:r}),S&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",disabled:r,onClick:()=>S(o.id,g),children:x("save","Save")})]}):e.jsx("div",{className:"nice-wiki__viewer",children:k==="html"?e.jsx("div",{className:"nice-wiki__html",dangerouslySetInnerHTML:{__html:F.Ts(g)}}):e.jsx("pre",{className:"nice-wiki__markdown",children:g})})]}):e.jsx("div",{className:"nice-wiki__empty",children:e.jsx("p",{children:x("selectPage","Select a page from the sidebar or create a new one.")})})}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Nn.displayName="NiceWiki";const Ea=[{code:"PL",label:"Polska",prefix:"PL",pattern:/^\d{10}$/,placeholder:"1234567890"},{code:"DE",label:"Deutschland",prefix:"DE",pattern:/^\d{9}$/,placeholder:"123456789"},{code:"GB",label:"United Kingdom",prefix:"GB",pattern:/^\d{9}(\d{3})?$/,placeholder:"123456789"},{code:"FR",label:"France",prefix:"FR",pattern:/^[A-Z0-9]{2}\d{9}$/,placeholder:"XX123456789"},{code:"CZ",label:"Česko",prefix:"CZ",pattern:/^\d{8,10}$/,placeholder:"12345678"},{code:"SK",label:"Slovensko",prefix:"SK",pattern:/^\d{10}$/,placeholder:"1234567890"},{code:"IT",label:"Italia",prefix:"IT",pattern:/^\d{11}$/,placeholder:"12345678901"},{code:"ES",label:"España",prefix:"ES",pattern:/^[A-Z0-9]\d{7}[A-Z0-9]$/,placeholder:"X1234567X"}],wn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g="",onChange:k,countryCode:K="PL",onCountryChange:ee,countries:X=Ea,showCountrySelector:S=!0,autoPrefixVat:v=!0,validationResult:I,onValidateRequest:j,placeholder:A},Y)=>{const b=F.rl(H,N);if(b==="hidden")return null;b==="disabled"&&(d=!0),b==="readOnly"&&(f=!0);const{t:h}=F.ue(),C=F.Os(N),w=a.useMemo(()=>X.find(R=>R.code===K)??X[0],[X,K]),O=a.useCallback(R=>{let y=R.toUpperCase();return w&&y.startsWith(w.prefix)&&(y=y.slice(w.prefix.length)),w?w.pattern.test(y):y.length>0},[w]),L=a.useCallback(R=>{const y=R.target.value.replace(/\s/g,"");k==null||k(y,O(y))},[k,O]),x=v&&g&&w&&!g.toUpperCase().startsWith(w.prefix)?`${w.prefix}${g}`:g,p=O(g);return e.jsxs("div",{ref:Y,id:C,className:`nice-vat-input nice-size-${_}${z?` ${z}`:""}${i||!p&&g.length>0?" nice-error":""}${d?" nice-disabled":""}`,style:V,children:[n&&e.jsxs("label",{className:"nice-vat-input__label",htmlFor:`${C}-input`,children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-vat-input__row",children:[S&&e.jsx("select",{className:"nice-vat-input__country",value:K,onChange:R=>ee==null?void 0:ee(R.target.value),disabled:d||f,children:X.map(R=>e.jsx("option",{value:R.code,children:R.prefix},R.code))}),e.jsx("input",{id:`${C}-input`,className:"nice-input nice-vat-input__field",type:"text",name:M,value:g,onChange:L,readOnly:f,disabled:d,placeholder:A??(w==null?void 0:w.placeholder),required:r,"aria-invalid":!p&&g.length>0}),j&&g.length>0&&e.jsx("button",{type:"button",className:"nice-vat-input__verify",disabled:d||!p,onClick:()=>j(v?x:g,K),title:h("verifyVat","Verify VAT number"),children:"🔍"})]}),I&&e.jsxs("div",{className:`nice-vat-input__result nice-vat-input__result--${I.valid?"valid":"invalid"}`,children:[I.valid?"✅":"❌"," ",I.companyName??I.error??(I.valid?h("vatValid","VAT number valid"):h("vatInvalid","VAT number invalid"))]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});wn.displayName="NiceVatInput";const Ta=[{id:"pl-23",label:"23%",rate:.23,countryCode:"PL",category:"standard",isDefault:!0},{id:"pl-8",label:"8%",rate:.08,countryCode:"PL",category:"reduced"},{id:"pl-5",label:"5%",rate:.05,countryCode:"PL",category:"reduced"},{id:"pl-0",label:"0%",rate:0,countryCode:"PL",category:"zero"},{id:"pl-zw",label:"zw.",rate:0,countryCode:"PL",category:"exempt"},{id:"pl-np",label:"n.p.",rate:0,countryCode:"PL",category:"exempt"}],$n=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g,onChange:k,rates:K,countryCode:ee,placeholder:X,showPercentage:S=!0},v)=>{const I=F.rl(H,N);if(I==="hidden")return null;I==="disabled"&&(d=!0),I==="readOnly"&&(f=!0);const{t:j}=F.ue(),A=F.Os(N),Y=a.useMemo(()=>{const h=K??Ta;return ee?h.filter(C=>!C.countryCode||C.countryCode===ee):h},[K,ee]),b=a.useCallback(h=>{const C=h.target.value,w=Y.find(O=>O.id===C);w&&(k==null||k(C,w))},[k,Y]);return e.jsxs("div",{ref:v,id:A,className:`nice-tax-rate nice-size-${_}${z?` ${z}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:V,children:[n&&e.jsxs("label",{className:"nice-tax-rate__label",htmlFor:`${A}-select`,children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("select",{id:`${A}-select`,className:"nice-select nice-tax-rate__select",name:M,value:g??"",onChange:b,disabled:d||f,required:r,children:[e.jsx("option",{value:"",disabled:!0,children:X??j("selectRate","Select rate…")}),Y.map(h=>e.jsxs("option",{value:h.id,children:[h.label,S&&h.category!=="exempt"?` (${(h.rate*100).toFixed(0)}%)`:""]},h.id))]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});$n.displayName="NiceTaxRatePicker";const Ra={asset:"var(--nice-color-info, #5bc0de)",liability:"var(--nice-color-warning, #f0ad4e)",equity:"var(--nice-color-success, #5cb85c)",revenue:"var(--nice-color-primary, #337ab7)",expense:"var(--nice-color-error, #d9534f)"},Mn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",name:M,id:N,className:z,style:V,accessMode:H,value:g,onChange:k,accounts:K,treeView:ee=!1,placeholder:X,searchable:S=!0,showType:v=!0,onSearch:I},j)=>{const A=F.rl(H,N);if(A==="hidden")return null;A==="disabled"&&(d=!0),A==="readOnly"&&(f=!0);const{t:Y}=F.ue(),b=F.Os(N),[h,C]=a.useState(""),[w,O]=a.useState(!1),L=a.useMemo(()=>{const u=s=>{for(const c of s){if(c.code===g)return c;if(c.children){const l=u(c.children);if(l)return l}}};return u(K)},[K,g]),x=a.useMemo(()=>{const u=[],s=c=>{for(const l of c)u.push(l),l.children&&s(l.children)};return s(K),u},[K]),p=a.useMemo(()=>{if(!h)return x;const u=h.toLowerCase();return x.filter(s=>s.code.toLowerCase().includes(u)||s.name.toLowerCase().includes(u))},[x,h]),R=a.useCallback(u=>{C(u),I==null||I(u),O(!0)},[I]),y=a.useCallback(u=>{k==null||k(u.code,u),O(!1),C("")},[k]);return e.jsxs("div",{ref:j,id:b,className:`nice-account-picker nice-size-${_}${z?` ${z}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:V,children:[n&&e.jsxs("label",{className:"nice-account-picker__label",htmlFor:`${b}-input`,children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-account-picker__control",children:S&&!f?e.jsx("input",{id:`${b}-input`,className:"nice-input",type:"text",value:w?h:L?`${L.code} — ${L.name}`:"",onChange:u=>R(u.target.value),onFocus:()=>{C(""),O(!0)},onBlur:()=>setTimeout(()=>O(!1),200),placeholder:X??Y("searchAccount","Search account…"),disabled:d,required:r}):e.jsx("div",{className:"nice-account-picker__display",children:L?`${L.code} — ${L.name}`:X??Y("selectAccount","Select account…")})}),w&&p.length>0&&e.jsx("div",{className:"nice-account-picker__dropdown",role:"listbox",children:p.map(u=>e.jsxs("div",{className:`nice-account-picker__option${u.code===g?" nice-account-picker__option--selected":""}${u.isActive===!1?" nice-account-picker__option--inactive":""}`,role:"option","aria-selected":u.code===g,onClick:()=>y(u),children:[v&&u.type&&e.jsx("span",{className:"nice-account-picker__type",style:{color:Ra[u.type]},title:u.type,children:"●"}),e.jsx("span",{className:"nice-account-picker__code",children:u.code}),e.jsx("span",{className:"nice-account-picker__name",children:u.name})]},u.code))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Mn.displayName="NiceAccountPicker";const Sn=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",id:M,className:N,style:z,accessMode:V,mode:H="manual",onScan:g,onModeChange:k,beepOnScan:K=!0,beepFrequency:ee=1800,beepDuration:X=150,placeholder:S,scanHistory:v=[],showHistory:I=!0,maxHistory:j=10,autoFocus:A=!0,onCameraFrame:Y},b)=>{const h=F.rl(V,M);if(h==="hidden")return null;h==="disabled"&&(d=!0),h==="readOnly"&&(f=!0);const{t:C}=F.ue(),w=F.Os(M),[O,L]=a.useState(""),x=a.useRef(null),p=a.useRef(null),R=a.useCallback(()=>{if(K)try{p.current||(p.current=new AudioContext);const s=p.current,c=s.createOscillator(),l=s.createGain();c.connect(l),l.connect(s.destination),c.frequency.value=ee,c.type="square",l.gain.value=.3,c.start(),c.stop(s.currentTime+X/1e3)}catch{}},[K,ee,X]),y=a.useCallback(()=>{var s;O.trim()&&(R(),g==null||g({value:O.trim(),format:"manual",scannedAt:new Date}),L(""),(s=x.current)==null||s.focus())},[O,g,R]),u=v.slice(0,j);return e.jsxs("div",{ref:b,id:w,className:`nice-scanner nice-size-${_}${N?` ${N}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:z,children:[n&&e.jsxs("div",{className:"nice-scanner__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-scanner__modes",children:[e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${H==="camera"?" nice-scanner__mode-btn--active":""}`,onClick:()=>k==null?void 0:k("camera"),disabled:d,children:["📷 ",C("camera","Camera")]}),e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${H==="manual"?" nice-scanner__mode-btn--active":""}`,onClick:()=>k==null?void 0:k("manual"),disabled:d,children:["⌨️ ",C("manual","Manual")]})]}),H==="camera"&&e.jsx("div",{className:"nice-scanner__camera",children:e.jsx("div",{className:"nice-scanner__viewfinder",children:e.jsxs("div",{className:"nice-scanner__viewfinder-overlay",children:[e.jsx("span",{children:"📷"}),e.jsx("p",{children:C("cameraPlaceholder","Camera preview — connect scanner adapter")})]})})}),H==="manual"&&!f&&e.jsxs("div",{className:"nice-scanner__manual",children:[e.jsx("input",{ref:x,className:"nice-input nice-scanner__input",type:"text",value:O,onChange:s=>L(s.target.value),onKeyDown:s=>s.key==="Enter"&&y(),placeholder:S??C("enterCode","Enter or scan code…"),disabled:d,autoFocus:A}),e.jsx("button",{type:"button",className:"nice-scanner__submit",onClick:y,disabled:d||!O.trim(),children:"✓"})]}),I&&u.length>0&&e.jsxs("div",{className:"nice-scanner__history",children:[e.jsx("div",{className:"nice-scanner__history-label",children:C("recentScans","Recent scans")}),u.map((s,c)=>e.jsxs("div",{className:"nice-scanner__history-item",children:[e.jsx("span",{className:"nice-scanner__history-value",children:s.value}),s.format&&e.jsx("span",{className:"nice-scanner__history-format",children:s.format}),e.jsx("span",{className:"nice-scanner__history-time",children:s.scannedAt.toLocaleTimeString()})]},c))]}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});Sn.displayName="NiceScannerControl";const En=a.forwardRef(({label:n,helperText:t,error:i,required:r,disabled:d,readOnly:f,size:_="md",id:M,className:N,style:z,accessMode:V,value:H="",onChange:g,onComplete:k,length:K=4,masked:ee=!0,showKeypad:X=!1,autoSubmit:S=!0,shake:v=!1,placeholderChar:I="·"},j)=>{const A=F.rl(V,M);if(A==="hidden")return null;A==="disabled"&&(d=!0),A==="readOnly"&&(f=!0);const{t:Y}=F.ue(),b=F.Os(M),h=a.useRef([]),[C,w]=a.useState(!1);a.useEffect(()=>{if(v){w(!0);const R=setTimeout(()=>w(!1),500);return()=>clearTimeout(R)}},[v]);const O=H.split("").slice(0,K);for(;O.length<K;)O.push("");const L=a.useCallback((R,y)=>{var c;const u=[...O];u[R]=y;const s=u.join("");g==null||g(s),y&&R<K-1&&((c=h.current[R+1])==null||c.focus()),S&&s.length===K&&s.indexOf("")===-1&&(k==null||k(s))},[O,K,g,k,S]),x=a.useCallback((R,y)=>{var u,s,c;R.key==="Backspace"&&!O[y]&&y>0&&((u=h.current[y-1])==null||u.focus(),L(y-1,"")),R.key==="ArrowLeft"&&y>0&&((s=h.current[y-1])==null||s.focus()),R.key==="ArrowRight"&&y<K-1&&((c=h.current[y+1])==null||c.focus())},[O,K,L]),p=a.useCallback(R=>{var y,u,s;if(R==="clear"){g==null||g(""),(y=h.current[0])==null||y.focus();return}if(R==="backspace"){const c=H.slice(0,-1);g==null||g(c);const l=Math.max(0,c.length-1);(u=h.current[l])==null||u.focus();return}if(H.length<K){const c=H+R;g==null||g(c),c.length<K&&((s=h.current[c.length])==null||s.focus()),S&&c.length===K&&(k==null||k(c))}},[H,K,g,k,S]);return e.jsxs("div",{ref:j,id:b,className:`nice-pin nice-size-${_}${C?" nice-pin--shake":""}${N?` ${N}`:""}${i?" nice-error":""}${d?" nice-disabled":""}`,style:z,children:[n&&e.jsxs("label",{className:"nice-pin__label",children:[n,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-pin__boxes",children:O.map((R,y)=>e.jsx("input",{ref:u=>{h.current[y]=u},className:"nice-pin__box",type:ee?"password":"text",inputMode:"numeric",maxLength:1,value:R,onChange:u=>{const s=u.target.value.replace(/\D/g,"");s.length<=1&&L(y,s)},onKeyDown:u=>x(u,y),disabled:d,readOnly:f,placeholder:I,"aria-label":`${Y("digit","Digit")} ${y+1}`},y))}),X&&!f&&e.jsx("div",{className:"nice-pin__keypad",children:["1","2","3","4","5","6","7","8","9","clear","0","backspace"].map(R=>e.jsx("button",{type:"button",className:`nice-pin__key${R==="clear"||R==="backspace"?" nice-pin__key--action":""}`,onClick:()=>p(R),disabled:d,children:R==="clear"?"C":R==="backspace"?"⌫":R},R))}),t&&e.jsx("span",{className:"nice-helper-text",children:t}),i&&typeof i=="string"&&e.jsx("span",{className:"nice-error-text",children:i})]})});En.displayName="NicePinCodeInput";exports.$=Xt;exports.A=En;exports.B=Un;exports.C=Sn;exports.E=bn;exports.F=$n;exports.G=cn;exports.H=wn;exports.I=Nn;exports.L=Zt;exports.M=pn;exports.O=hn;exports.P=at;exports.Q=tt;exports.R=Gt;exports.S=Je;exports.T=Yt;exports.U=ft;exports.V=qe;exports.W=We;exports.X=Se;exports.Y=Ut;exports.Z=Wt;exports._=qt;exports.a=Mn;exports.a0=yt;exports.a1=nt;exports.a2=Zn;exports.a3=sa;exports.b=yn;exports.c=tn;exports.d=kt;exports.f=Qt;exports.g=jn;exports.i=_n;exports.j=Vn;exports.k=xn;exports.l=Xn;exports.n=en;exports.o=vt;exports.q=mn;exports.r=fn;exports.s=nn;exports.t=kn;exports.u=rn;exports.v=Fn;exports.w=gn;exports.x=ln;exports.y=Cn;exports.z=dn;
|